Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As already mentioned, you've specified the <code>REG_OPTION_BACKUP_RESTORE</code> option in the call to <code>RegCreateKeyEx</code>, which means that you're opening the key in order to perform a backup or restore. Ordinarily, you would use <code>REG_OPTION_NON_VOLATILE</code> instead.</p> <p>What operating system are you running? In Windows 2000/XP, the <code>HKEY_LOCAL_MACHINE</code> registry hive is not writeable by non-administrator users, so <code>RegCreateKeyEx</code> will fail with an access denied error (error 5). This also applies to Vista, if your application has a <code>requestedExecutionLevel</code> entry in its manifest. If you're running Vista, and your application doesn't specify a <code>requestedExecutionLevel</code> (or if it doesn't have a manifest at all), access to <code>HKEY_LOCAL_MACHINE</code> will be virtualised, so <code>RegCreateKeyEx</code> should succeed. See <a href="http://msdn.microsoft.com/en-us/library/bb530198.aspx" rel="nofollow noreferrer">Registry Virtualization in Windows Vista</a> in MSDN for more details.</p> <p>There are some more problems with the code you've posted, which will only become apparent if you compile your project with <code>UNICODE</code> defined. This line:</p> <pre><code>LPCTSTR data = "OtherTestData\0"; </code></pre> <p>should be</p> <pre><code>LPCTSTR data = TEXT("OtherTestData\0"); </code></pre> <p>and this line:</p> <pre><code>LONG setRes = RegSetValueEx(hKey, value, 0, REG_SZ, (LPBYTE)data, _tcslen(data)+1); </code></pre> <p>should be:</p> <pre><code>LONG setRes = RegSetValueEx(hKey, value, 0, REG_SZ, (LPBYTE)data, (_tcslen(data)+1) * sizeof(TCHAR)); </code></pre> <p>because the <code>cbData</code> parameter in <code>RegSetValueEx</code> is the length of the data in bytes, not characters.</p> <p>I hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload