我正在使用GetSubKeysNames函数从{HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall}获取子项。但它返回不同的子键计数。在C#中返回371个子键,在visual basic中返回61个子键。我哪里错了?
这是一些代码和图片。
C#
string[] deneme = unistallKey.GetSubKeyNames();
VB
Dim deneme() As String = UninstallKey.GetSubKeyNames
答案 0 :(得分:1)
我遇到同样的问题,使用下面的代码解决了问题。
Dim rk1 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _
(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64)
Dim rk2 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _
(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64)
Dim rk3 As RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _
(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64)
rk1 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
regpath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
rk2 = rk1.OpenSubKey(regpath)
For Each subk As String In rk2.GetSubKeyNames
rk3 = rk2.OpenSubKey(subk, False)
value = rk3.GetValue("DisplayName", "")
If value <> "" Then
includes = True
If value.IndexOf("Hotfix") <> -1 Then includes = False
If value.IndexOf("Security Update") <> -1 Then includes = False
If value.IndexOf("Update for") <> -1 Then includes = False
If value.IndexOf("Service Pack") <> -1 Then includes = False
For vAtual = 0 To UBound(Softwares)
If value = Softwares(vAtual) Then
includes = False
End If
Next
If includes = True Then
gridSoft.Rows.Add(value, rk3.GetValue("InstallDate", ""), rk3.GetValue("UninstallString", ""), rk3.GetValue("EstimatedSize", ""), rk3.GetValue("InstallLocation", ""), rk3.GetValue("Publisher", ""))
Softwares(vCont) = value
vCont = vCont + 1
End If
End If
Next
答案 1 :(得分:0)
可能有些程序是在32位下安装的,有些是在64位以下。 通过以下密钥枚举:
HKEY_LOCAL_MACHINE \ SOFTWARE \ WOW6432node \