- //设置注册表指定的键值
- bool SetRegValue(string path,string sSetKey,DWORD dValue)
- {
- try
- {
- string sErrorMsg;
- wstring ss = AsciiToUnicode(path);
- HKEY hkey;
- LONG rt = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,ss.c_str(),0, KEY_ALL_ACCESS,&hkey);
- if(rt != ERROR_SUCCESS)
- {
- ::RegCloseKey(hkey);
- sErrorMsg = sSetKey + ": open reg root key failed";
- throw sErrorMsg;
- }
- else
- {
- LPBYTE lpb = (LPBYTE)&dValue;
- DWORD length = sizeof(lpb);
- LONG rt = ::RegSetValueEx(hkey,AsciiToUnicode(sSetKey).c_str(),NULL,REG_DWORD,lpb,length);
- if(rt != ERROR_SUCCESS)
- {
- ::RegCloseKey(hkey);
- sErrorMsg = sSetKey + "set the needsetkey value failed!";
- throw sErrorMsg;
- }
- ::RegCloseKey(hkey);
- }
- }
- catch(string sErrorMsg)
- {
- cout<<sErrorMsg.c_str()<<endl;
- return false;
- }
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
- return true;
- }
转载于:https://blog.51cto.com/venglu/1185210