0

我正在使用 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

在此处输入图像描述

4

2 回答 2

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
于 2016-04-28T11:24:14.987 回答
0

可能是您的某些程序安装在 32 位以下,而有些则安装在 64 位以下。通过以下键枚举:

HKEY_LOCAL_MACHINE\Software\WOW6432node\

于 2012-11-22T13:49:09.390 回答