#include <afx.h>
#include <windows.h>void main()
{
CString str = "192.168.11.220 www.csdn.net";
// CHostFile hostFile("D:\\WINDOWS\\system32\\drivers\\etc\\hosts");
// CString s = str + "\r\n" + hostFile.str + "\r\n";

// hostFile.WriteToHost(s);
HKEY hKey = NULL;
HKEY hSubKey = NULL;
HKEY hSubKeyy = NULL;
RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains", &hKey);
RegCreateKey(hKey, "sina.com.cn", &hSubKey);
RegCreateKey(hSubKey, "www", &hSubKeyy);
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\sina.com.cn\\www", 0, KEY_SET_VALUE, &hSubKeyy);
DWORD dw = 2;
RegSetValueEx(hSubKeyy, "http", 0, REG_DWORD, (BYTE*)&dw, sizeof(DWORD)); CFile file("D:\\WINDOWS\\system32\\drivers\\etc\\hosts", CFile::modeReadWrite);
}

解决方案 »

  1.   

    支持老大 flyelf(空谷清音) GetLastError看看是什么原因
      

  2.   

    哎,偶是在98虚拟机上面运行上面的程序的,没有办法调试,自己的机子又是NTFS格式装不了98所以很郁闷啊,有哪些可能大家能告诉我吗?
      

  3.   

    CFile file("D:\\WINDOWS\\system32\\drivers\\etc\\hosts", CFile::modeReadWrite);
    '双启动?2000没这个系统目录
      

  4.   

    D:\\WINDOWS\\system32\\drivers\\etc\\hosts2000好像是WINNT吧
    D:\\WINNT\\system32\\drivers\\etc\\hosts
    试试
      

  5.   

    98,xp:   系统盘都是windows
    2000;    系统盘是winnt.
      

  6.   

    1.D:\\WINDOWS\\system32\\drivers\\etc\\hosts位置确定是正确的吗?
    2.CHostFile类的实现是不是有win98下不可用的API
    3.注册表的位置是否一致
    4.单步调试看看错语发生在什么地方
    5.可以用 flyelf(空谷清音) 说的GetLastError方法找出错误的原因希望对你有所帮助哦!!!