读取注册表项值 [英] Read a registry key value
问题描述
我正在尝试使用以下代码读取简单的注册表键值:
I was trying to read a simple registry keyvalue using the below code:
Dim aa As Object
aa = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Avira\\AntiVir Desktop", "LastCommandLine", Nothing)
变量值始终为空.
我在这里做错什么了?
请指教.
然后我在C#代码中尝试了同样的方法,并且可以正常工作.
代码如下:
aa variable value is always Nothing.
What am I doing wrong here?
Please advise.
Then I tried the same in C# code and its working fine.
The code is As below:
object aa = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Avira\\AntiVir Desktop","LastCommandLine",null);
推荐答案
Try
Dim aa As Object
aa = Registry.GetValue("HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop", "LastCommandLine", Nothing)
你知道为什么吗?您真正需要的关键值是"HKEY_CURRENT_USER \ Software \ Avira \ AntiVir Desktop";而双"\\"仅表示通过C#语法转义了"\",而不是VB.NET.要使C#代码相似,请使用详细修饰符``@'':
Can you see why? The key value you really need is "HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop"; and the double ''\\'' simply means escaped ''\'', by C# syntax, not VB.NET. To make C# code similar, use verbose modifier ''@'':
object aa = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop","LastCommandLine", null);
现在好多了? :-)
Better now? :-)
这篇关于读取注册表项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!