title: try to change ActivePowerScheme: RegOpenKeyEx failed with error 0
body: <p>I need to set ActivePowerScheme by changing it in registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes.
  So I try to do it with winapi functions RegOpenKeyEx and RegSetValueEx </p>
  
  <pre><code>wchar_t *PowerScheme=TEXT("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c");
  HKEY hRootKey = HKEY_LOCAL_MACHINE;
  PWCHAR sKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Power\\User\\PowerSchemes");
  PWCHAR sActivePowerS = TEXT("ActivePowerScheme"); 
  HKEY hKeyResult = NULL; 
  //open  
  if (RegOpenKeyEx(hRootKey,sKey,0,KEY_ALL_ACCESS,&amp;hKeyResult)!=ERROR_SUCCESS) {
        //it is always failing with error 0 !
        DWORD dw = GetLastError();  
  }
  </code></pre>
  
  <p>But RegOpenKeyEx() is always failing with error 0, that means "Operation completed successfully". And RegSetValueEx() returns same value. </p>
  
  <pre><code>if(RegSetValueEx(hKeyResult,sActivePowerS,0,REG_SZ,
           (BYTE *)PowerScheme,wcslen(PowerScheme))!=ERROR_SUCCESS) {
                  //it is always failing with error 0
                  DWORD dw = GetLastError();  
              }
  </code></pre>
  
  <p>And of course current power scheme doesn't change value. But according to msdn:
  "If the function succeeds, the return value is ERROR_SUCCESS.
   If the function fails, the return value is a nonzero error code".</p>
  
  <p>I will be grateful to any your answers. </p>
  
  <p>P.S. it compiled in Windows 7 and executed with rights of admin</p>