1. //设置注册表指定的键值 
  2. bool SetRegValue(string path,string sSetKey,DWORD dValue) 
  3. {     
  4.     try 
  5.     { 
  6.         string sErrorMsg; 
  7.         wstring ss = AsciiToUnicode(path); 
  8.         HKEY hkey; 
  9.  
  10.         LONG rt = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,ss.c_str(),0, KEY_ALL_ACCESS,&hkey); 
  11.  
  12.         if(rt != ERROR_SUCCESS) 
  13.         {     
  14.             ::RegCloseKey(hkey); 
  15.             sErrorMsg =  sSetKey + ": open reg root key failed"
  16.             throw sErrorMsg; 
  17.         } 
  18.         else 
  19.         { 
  20.             LPBYTE lpb = (LPBYTE)&dValue; 
  21.             DWORD length = sizeof(lpb); 
  22.  
  23.             LONG rt = ::RegSetValueEx(hkey,AsciiToUnicode(sSetKey).c_str(),NULL,REG_DWORD,lpb,length); 
  24.             if(rt != ERROR_SUCCESS) 
  25.             { 
  26.                 ::RegCloseKey(hkey); 
  27.  
  28.                 sErrorMsg = sSetKey + "set the needsetkey value failed!"
  29.                 throw sErrorMsg; 
  30.             } 
  31.  
  32.             ::RegCloseKey(hkey); 
  33.         } 
  34.     } 
  35.     catch(string sErrorMsg) 
  36.     { 
  37.         cout<<sErrorMsg.c_str()<<endl; 
  38.      
  39.         return false
  40.  
  41.     } 
  42.  
  43.     SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); 
  44.     return true