天天看點

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.