In attempting to upgrade some C++ software to run in Windows 7 I have experienced some problems in being able to create registry keys from scratch.
This is my code:
//
// Create a brand new registry key
//
LONG Registry::CreateRegister( std::string path )
{
HKEY hKey;
DWORD dwDisposition;
LONG openRes = RegCreateKeyEx( HKEY_CLASSES_ROOT,
path.c_str(),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition );
RegCloseKey( hKey );
return openRes;
}
In Windows XP, the RegCreateKeyEx function successfully creates the registry key, returning a success (0) value. In Windows 7 I am getting a return value of 5 (access denied) from the same function.
I used the regedit tool to ensure that my account has the necessary full permissions, but without success. Can anyone see where I might be going wrong, or if there are other gotchas and known issues I need to be aware of when using Visual Studio within Windows 7?
The software is currently written in Visual Studio 2003.
Thanks in anticipation.
Since Vista, access to certain areas of the registry has been locked down. The user must have “elevated” permissions. Try running your program with “Run as administrator” (right click it in Explorer).