Reading and writing to x86 and x64 registry keys from the same application

前端 未结 1 576
無奈伤痛
無奈伤痛 2020-12-06 10:39

I am running my application compiled as x86, and it is running on 64 bit Windows.

In order to fix a problem with ClickOnce file associations I want to read some CLS

1条回答
  •  既然无缘
    2020-12-06 11:15

    I might be misunderstanding what you're asking but if you're running in a 32bit process then all your keys will be in the Wow6432Node\xxxxx node anyway. So if you tried to copy them from HKEY_CURRENT_USER\Software\Classes\CLSID\{my clsid} (and didn't specify the 64 bit view manually) to HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{my clsid} you would be copying the same values. This code should work:

    keyPath = @"Software\Classes\CLSID\" + clsid;
    var regularx86View = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
    // Note this calls HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{my clsid}:
    var regularClassKey = regularx86View.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadSubTree); 
    
    var regularx64View = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
    // Note this calls HKEY_CURRENT_USER\Software\Classes\CLSID\{my clsid}:
    var regularClassKey = regularx64View.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadSubTree); 
    

    0 讨论(0)
提交回复
热议问题