Registry.GetValue始终返回null

编程入门 行业动态 更新时间:2024-10-25 03:19:13
本文介绍了Registry.GetValue始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在注册表中有以下密钥:

在以下位置: HKEY_LOCAL_MACHINE\SOFTWARE\RSA 具有值对象调用- WebExControlManagerPath ,其值是 c:\

我正试图这样做:

var r = Registry.GetValue(@ HKEY_LOCAL_MACHINE\SOFTWARE\ \RSA, WebExControlManagerPth,null); if(r!= null) ProcessAsUser.Launch(ToString());

但是 r 的值始终为空。 / p>

有什么想法吗?

解决方案

您不会以相同的方式访问HKEY_LOCAL_MACHINE配置单元在C#中,就像在批处理脚本中一样。您这样调用 Registry.LocalMachine :

RegistryKey myKey = Registry .LocalMachine.OpenSubKey(@ Software\RSA,false); 字符串值=(String)myKey.GetValue( WebExControlManagerPth); if(!String.IsNullOrEmpty(value)) { ProcessAsUser.Launch(ToString()); }

更新:

如果返回null,则将构建体系结构设置为任何CPU 。操作系统可能会不同地虚拟化32位和64位注册表。请参阅: http:// msdn .microsoft / en-us / library / windows / desktop / aa965884%28v = vs.85%29.aspx ,从32位应用程序中读取64bit注册表和 msdn.microsoft/zh-cn/library/windows/desktop/ms724072%28v=vs.85%29.aspx 。

I have the following key in my registry:

under:HKEY_LOCAL_MACHINE\SOFTWARE\RSA I have value object call - WebExControlManagerPath and its value is c:\

I am trying to do this:

var r = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\RSA", "WebExControlManagerPth",null); if(r!=null) ProcessAsUser.Launch(ToString());

But r value is always null.

Any ideas?

解决方案

You don't access the HKEY_LOCAL_MACHINE hive the same way you do in C# as you would in batch scripting. You call Registry.LocalMachine, as such:

RegistryKey myKey = Registry.LocalMachine.OpenSubKey( @"Software\RSA", false); String value = (String)myKey.GetValue("WebExControlManagerPth"); if (!String.IsNullOrEmpty(value)) { ProcessAsUser.Launch(ToString()); }

Update:

If it returns null, set your build architecture to Any CPU. The operating system may virtualize 32-bit and 64-bit registries differently. See: msdn.microsoft/en-us/library/windows/desktop/aa965884%28v=vs.85%29.aspx, Reading 64bit Registry from a 32bit application, and msdn.microsoft/en-us/library/windows/desktop/ms724072%28v=vs.85%29.aspx.

更多推荐

Registry.GetValue始终返回null

本文发布于:2023-11-09 10:05:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Registry   GetValue   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!