开发者

Read registry key

Am I doing something wrong? I get no value back...

Imports Microsoft.Win32
...
Dim s As String = ""
Dim reg As RegistryKey

reg =Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Window开发者_如何学Cs\CurrentVersion\Run", True)
s = reg.GetValue("RtHDVCpl", "")
MsgBox(s)
reg.Close()


If you get no exception then you can safely assume that the value does not exist or has an empty string as its value.

If you are sure that the value in fact exists then the next explanation is that your machine runs a 64-bit operating system. Where the registry is virtualized for 32-bit processes. They will read values from HKLM\Software\Wow6432Node. And that you're running VS2010, it forces projects to run in 32-bit by default. Project + Properties, Compile tab, scroll down, Advanced Compile Options. Change Target CPU to AnyCPU. Not available in the Express edition afaik, you'd have to edit the .vbproj file by hand.


Try messagebox.show(s.ToString)

Wehn you compile to 32 bit on a 64 bit OS, when the key will be created in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ node. However, the app that creates it should be able to read it back, even if you can't find it where you expected to in RegEdit.exe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜