+ -
当前位置:首页 → 问答吧 → 修改注册表键值的问题

修改注册表键值的问题

时间:2011-12-12

来源:互联网

我想把 注册表键: HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings
  注册表值: ProxyEnable 
把他的初始值0改为一,下面代码不知道哪出来问题,求各位帮帮忙,谢谢了!!!!!
C/C++ code

HKEY hkey;
LPCSTR data_Set="Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable";
LONG res;
DWORD datatype=REG_DWORD;
unsigned char szvalue[5];
strcpy((char*)szvalue,"1");

res =::RegOpenKeyEx(HKEY_CURRENT_USER,
data_Set, 0,
KEY_WRITE|KEY_READ, &hkey);

if(res!=ERROR_SUCCESS)
{
MessageBox(NULL,"找到了,呵呵!","提示",MB_OK);
}
res = ::RegSetValueEx(hkey, "ProxyEnable", 0, datatype, szvalue, strlen(LPCSTR(szvalue)));


if(res==ERROR_SUCCESS)
MessageBox(NULL,"成功","Title(标题)",MB_OK);
else
MessageBox(NULL,"失败","Title(标题)",MB_OK);
RegCloseKey(hkey);


作者: ihaohang   发布时间: 2011-12-12

HKEY hkey;
//(a)LPCSTR data_Set="Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable";
LPCSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\"; //(b)
LONG res;
DWORD datatype=REG_DWORD;
//(c)
//unsigned char szvalue[5];
//strcpy((char*)szvalue,"1");
DWORD dwValue = 1;

res =::RegOpenKeyEx(HKEY_CURRENT_USER,
data_Set, 0,
KEY_WRITE|KEY_READ, &hkey);

//(d) if(res!=ERROR_SUCCESS)
if(res==ERROR_SUCCESS)
{
MessageBox(NULL,"找到了,呵呵!","提示",MB_OK);
}
//(e)res = ::RegSetValueEx(hkey, "ProxyEnable", 0, datatype, szvalue, strlen(LPCSTR(szvalue)));
res = ::RegSetValueEx(hkey, "ProxyEnable", 0, datatype, (CONST BYTE*)&dwValue, sizeof(DWORD));

if(res==ERROR_SUCCESS)
MessageBox(NULL,"成功","Title(标题)",MB_OK);
else
MessageBox(NULL,"失败","Title(标题)",MB_OK);
RegCloseKey(hkey);

作者: yoke_wolf   发布时间: 2011-12-13

热门下载

更多