2012-11-27 84 views
0

Windows7和Win64是一個新的平臺我,編程明智,所以不知道發生了什麼,我用windows7 64bit下的命令保存在Windows註冊表中的一個鍵,問題是相同的代碼是能夠返回REG_OPENED_EXISTING_KEY返回值,這意味着密鑰創建是成功的,並且該函數能夠在後續調用中讀取/打開密鑰,但是當我嘗試在regedit.exe中找到位置的密鑰時,我不能在HKLM_LOCAL_MACHINE/Software/MyProject和HKLM_LOCAL_MACHINE/Software/Wow6432Node/MyProject中都不會顯示在樹中。我的註冊表條目在哪裏? Windows 7和Win64

任何人都可以清楚這裏發生了什麼嗎?

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; 
} 
+0

您是否以管理員身份運行?你有沒有註冊表虛擬化? –

+0

@Roger否我不是,我的程序也不是,即使當我以管理員身份運行regedit.exe時,我看不到條目。不確定註冊表可視化是什麼。 – StudentX

回答

1

如果您的進程沒有以管理員身份運行,將無法訪問HKLM\SOFTWARE。出於兼容性原因,Windows Vista和Windows 7將應用名爲「registry virtualization」的東西。這將訪問HKLM \ SOFTWARE重定向到您的進程可以訪問的某處。它爲嘗試寫入C:\Program Files的傳統進程執行類似的操作。

Windows如何決定您的應用程序是「傳統」並需要此兼容性破解?您需要一個application manifest來告訴Windows,您的進程支持Windows Vista,並且您不需要黑客入侵。

+0

我已經發布了以下更改,請看看。我究竟做錯了什麼? – StudentX

+0

對不起票務需要15聲望:P – StudentX

0

我將以下清單文件添加到項目中,並將CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST「MyProject.exe.Manifest」添加到resource.rc文件。瞧。

**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> 
相關問題