修改注册表键值的问题 - C++ Builder / Windows SDK/API我想把 注册表键: HKCU\Software\Microsoft\Window
修改注册表键值的问题 - C++ Builder / Windows SDK/API
我想把 注册表键: HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings
注册表值: ProxyEnable
把他的初始值0改为一,下面代码不知道哪出来问题,求各位帮帮忙,谢谢了!!!!!
C/C++ codeHKEY 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);elseMessageBox(NULL,"失败","Title(标题)",MB_OK);RegCloseKey(hkey);
[解决办法]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);
[解决办法]#include <Registry.hpp>
TRegistry *reg=new TRegistry;
reg->RootKey=HKEY_CURRENT_USER;
reg->OpenKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings",false);
reg->WriteInterger("ProxyEnable",1);
delete reg;