#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);
}
#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);
}
'双启动?2000没这个系统目录
D:\\WINNT\\system32\\drivers\\etc\\hosts
试试
2000; 系统盘是winnt.
2.CHostFile类的实现是不是有win98下不可用的API
3.注册表的位置是否一致
4.单步调试看看错语发生在什么地方
5.可以用 flyelf(空谷清音) 说的GetLastError方法找出错误的原因希望对你有所帮助哦!!!