在.Net Core应用程序中访问32位hive
在 64 位计算机上访问 32 位注册表配置单元的正确方法是什么?我尝试使用以下代码在 HKCU\Software 32 位配置单元中设置一些值,但它仍然获得 64 位配置单元。我找不到任何替代 api 来传递 RegistryView
枚举,在 C++ 中,可以在打开/创建密钥时指定 Wow64 标志,但我在 Microsoft.Win32
库中没有找到类似的用法。
[SupportedOSPlatform("Windows")]
void SetValue()
{
using var key = GetOrCreateKey(RegistryHive.CurrentUser,
RegistryView.Registry32,
@"SOFTWARE\MyApp\Key"
);
key?.SetValue("Value", 1);
}
[SupportedOSPlatform("Windows")]
static RegistryKey? GetOrCreateKey(RegistryHive hive, RegistryView view, string keyPath)
{
using var baseKey = RegistryKey.OpenBaseKey(hive, view);
var subKey = baseKey?.OpenSubKey(keyPath);
if (subKey != null)
{
return subKey;
}
return baseKey?.CreateSubKey(keyPath);
}
在 64 位计算机上,我希望在 HKEY_CURRENT_USER\Software\Wow6432Node\MyApp\Key
上的键上设置该值,但它被写入 HKEY_CURRENT_USER\Software\MyApp\Key
What is the correct way to access 32 bit registry hive on a 64 bit machine? I tried the following code to set some value in HKCU\Software 32 bit hive but it still gets the 64 bit hive. I couldnt find any alternate api to pass RegistryView
enum, In C++ the Wow64 flag can be specified when opening/creating a key but I dont find similar usage in Microsoft.Win32
library.
[SupportedOSPlatform("Windows")]
void SetValue()
{
using var key = GetOrCreateKey(RegistryHive.CurrentUser,
RegistryView.Registry32,
@"SOFTWARE\MyApp\Key"
);
key?.SetValue("Value", 1);
}
[SupportedOSPlatform("Windows")]
static RegistryKey? GetOrCreateKey(RegistryHive hive, RegistryView view, string keyPath)
{
using var baseKey = RegistryKey.OpenBaseKey(hive, view);
var subKey = baseKey?.OpenSubKey(keyPath);
if (subKey != null)
{
return subKey;
}
return baseKey?.CreateSubKey(keyPath);
}
On 64 bit machine, I want the value to be set on key on HKEY_CURRENT_USER\Software\Wow6432Node\MyApp\Key
but its getting written on HKEY_CURRENT_USER\Software\MyApp\Key
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论