天天看点

64位读取注册表与32位的区别

有一个读取注册表信息的程序  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkeystring , 0, KEY_READ, &hKey) == ERROR_SUCCESS)/

,在32位下完全正常,但是在64位返回值正确,但就是读不到东西。后来单步发现读不到东西,就搜64位读注册表失败,发现需要加

if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkeystring , 0,KEY_READ|KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)就可以了,我是全部把权限提高,还可以根据不同的操作系统,设置不同的参数。

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

IsWow64返回TRUE则是64位系统,否则为32位系统。

BOOL IsWow64()

{

    BOOL bIsWow64 = FALSE;

    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(

        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(NULL != fnIsWow64Process)

    {

        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))

        {

                        return FALSE;

        }

    }

    return bIsWow64;

}

可参考的文献:

http://msdn.microsoft.com/en-us/library/aa384129(v=VS.85).aspx

http://www.codeproject.com/Articles/51326/Net-Compilation-registry-accessing-and-applicatio

http://boluns.blog.163.com/blog/static/69845968201071132032313/

Hide   Shrink 

64位读取注册表与32位的区别

   Copy Code

The OpenSubKey will return the searched key, allowing you to specify reading from the normal registry, or from the alternative 32-bit, WOW64 registry. The following example reads from the 32-bit WOW64 registry:

Hide   Copy Code

You just need to place your key name where “[Key]” is.