OpenSubKey()方法返回Nothing [英] OpenSubKey() method returns Nothing
问题描述
我正在尝试从安装程序的注册表中提取卸载字符串。
我已编写以下代码来循环程序。
Dim 软件作为 字符串 = 没什么
' 注册表项将保存在字符串SoftwareKey中。
Dim SoftwareKey 正如 字符串 = SOFTWARE \ Microsoft \ Windows \ CurrentVersion \Installer \ UserData \S-1-5-18 \Products
' \ UserData \S-1-5-18 \Products
使用 rk 作为 RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
用于 每个 skName 在 rk.GetSubKeyNames
下一步
结束 使用
但是我从OpenSubKey()方法得到null / Nothing,如果我放弃以下路径HKEY_LOCAL_MACHINE\SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Installer它是返回值。
我已经检查了注册表中的完整路径,它存在于那里。通过更改权限尝试,这是行不通的。你能帮帮忙吗?
我使用的是Windows 7 64位操作系统
确保根据机器配置打开正确的配置单元(64或32位)。
此代码可能对你更好;
Sub Main()
使用 hklm As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,IIf(Environment.Is64BitOperatingSystem,RegistryView.Registry64,RegistryView.Registry32))
使用键 As RegistryKey = hklm.OpenSubKey( SOFTWARE \ Microsoft \ Windows \ CurrentVersion \\ \\ _Installer \ UserData \S-1-5-18 \产品)
Console.WriteLine(键)
结束 Usi ng
结束 使用
结束 Sub
希望这有帮助,
弗雷德里克
Hi,
I am trying to extract uninstall string from the registry for the programs installed.
I have written the following code to loop thorough the programs.
Dim Software As String = Nothing
'The registry key will be held in a string SoftwareKey.
Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
'"\UserData\S-1-5-18\Products"
Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
For Each skName In rk.GetSubKeyNames
Next
End Using
But i am getting null/Nothing from the OpenSubKey() method, If i give up to the following path "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer" it is returning value.
I have checked the full path in registry, it exists there. Tried by changing permissions also, which is not working. Can you help?
I am using Windows 7 64 bit OS
Make sure you open the correct hive depending on machine configuration (64 or 32 bit).
This code might work better for you;
Sub Main() Using hklm As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, IIf(Environment.Is64BitOperatingSystem, RegistryView.Registry64, RegistryView.Registry32)) Using key As RegistryKey = hklm.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products") Console.WriteLine(key) End Using End Using End Sub
Hope this helps,
Fredrik
这篇关于OpenSubKey()方法返回Nothing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!