Question

Windows7 and Win64 is a new platform me, programming wise, so don't know what happened, I save a key in windows registry in windows7 64bit with the following command, the problem is that the same code is able to return REG_OPENED_EXISTING_KEY return value, which means the key creation was success and that the function is able to read/open the key in subsequent calls, but when I try to find the key in the location in regedit.exe, I can't it simply doesn't show in the tree neither in HKLM_LOCAL_MACHINE/Software/MyProject nor in HKLM_LOCAL_MACHINE/Software/Wow6432Node/MyProject

Can anybody please clear what's happening here ?

 HKEY hKey ;
 HKEY  key = HKEY_LOCAL_MACHINE;
 DWORD disValue ;
 string subKey = "Software\\MyProject\\";

 LONG retValue = RegCreateKeyEx( key, subKey.c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &disValue ) ;
 if ( retValue == ERROR_SUCCESS )
 {
    if ( disValue == REG_CREATED_NEW_KEY )// new key created. This value will change to REG_OPENED_EXISTING_KEY if the key already existed, the function then simply open the key.
       return true;
    return false;
 }
Was it helpful?

Solution

If your process is not running as Administrator, it will be unable to access HKLM\SOFTWARE. For compatibility reasons, Windows Vista and Windows 7 will then apply something called "registry virtualization". This redirects accesses to HKLM\SOFTWARE to somewhere that your process can access. It does something similar for legacy processes that attempt to write to C:\Program Files.

How does Windows decide that your application is "legacy" and needs this compatibility hack? You need an application manifest to tell Windows that your process is Windows Vista-aware and that you don't want the hack.

OTHER TIPS

I added the following manifest file to the project and added CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyProject.exe.Manifest" to the resource.rc file. And voila.

**MyProject.exe.Manifest**

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
  xmlns="urn:schemas-microsoft-com:asm.v1"
  manifestVersion="1.0">

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application> 
      <!--This Id value indicates the application supports Windows Vista functionality -->
    <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
      <!--This Id value indicates the application supports Windows 7 functionality-->
    <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    </application> 
</compatibility>

<assemblyIdentity
    name="MyCompany.Apps.MyProject"
    processorArchitecture="*"
    version="1.0.0.0"
    type="win32"/>
<description>App description</description>
<dependency>
    <dependentAssembly>
    <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="*"
        publicKeyToken="6595b64144ccf1df"
        language="*"
    />
    </dependentAssembly>
</dependency>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
    <requestedPrivileges>
        <requestedExecutionLevel
        level="requireAdministrator"
        uiAccess="false"/>
    </requestedPrivileges>
</security>
</trustInfo>
</assembly>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top