Search This Blog

Thursday, April 16, 2009

Registry Write example by enable Proxy settings

void EnableProxy()
{
     HKEY hkResult;
     LPCTSTR lpValueName = "VALUE_NAME";
     LPCTSTR lpszKeyName = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
     LPCTSTR lpszValueName = "ProxyEnable";
     // Opens a key in the registry and keeps an handle - hkResult - for future use.
     LONG Res = RegCreateKeyEx (HKEY_CURRENT_USER, lpszKeyName,
          0,NULL,
          REG_OPTION_NON_VOLATILE ,KEY_ALL_ACCESS,NULL, &hkResult,
          NULL);
     if (Res != ERROR_SUCCESS)
          throw "Unable to open the key";

     // Write value in the registry
     DWORD dwData;
     dwData=1;
     Res=RegSetValueEx(hkResult, TEXT(lpszValueName),0, REG_DWORD,(const BYTE*) &dwData, sizeof(DWORD));
     if (Res != ERROR_SUCCESS)
          throw "Unable to set value";


     Res = RegCloseKey(hkResult);    

}

No comments: