Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从注册表项获取值_Vb.net_Registry - Fatal编程技术网

Vb.net 从注册表项获取值

Vb.net 从注册表项获取值,vb.net,registry,Vb.net,Registry,当我试图从注册表中获取一个值并在DataGridView上显示时,该值与注册表中存在的值不同。 这发生在DisplayVersion上,有时也发生在DisplayName上。 注册表上的值: 我的应用程序上的值: 我的代码是: Dim _regKeysFind() As String = {"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", "S

当我试图从注册表中获取一个值并在
DataGridView
上显示时,该值与注册表中存在的值不同。

这发生在
DisplayVersion
上,有时也发生在
DisplayName
上。

注册表上的值


我的应用程序上的值:



我的代码是:

Dim _regKeysFind() As String = {"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
                                "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"}
    Try
        _dTableApps = New DataTable()
        With _dTableApps
            .Columns.Add("Aplicacao")
            .Columns.Add("Versao")
            .Columns.Add("Fabricante")
            .Columns.Add("x64")
        End With
        For Each _regKeyString As String In _regKeysFind
            Using _regKey As RegistryKey = Registry.LocalMachine.OpenSubKey(_regKeyString)
                For Each _subRegKey As String In _regKey.GetSubKeyNames
                    Try
                        'Get sub keys
                        With _regKey.OpenSubKey(_subRegKey)
                            Dim _name = "", _version As String = "",
                            _installLocation = "", _publisher = "",
                             _systemComponent = "", _releaseType = ""
                            Try
                                Dim _text As New TextBox
                                _text.Text = .GetValue("DisplayName").ToString
                                _name = _text.Text
                                _text = Nothing
                            Catch ex As Exception
                            End Try
                            Try                                    
                                _version &= .GetValue("DisplayVersion").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _installLocation = .GetValue("InstallLocation").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _publisher = .GetValue("Publisher").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _systemComponent = .GetValue("SystemComponent").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _releaseType = .GetValue("ReleaseType").ToString.ToLower
                            Catch ex As Exception
                            End Try
                            If (_name.ToString <> "" And _systemComponent <> "1" And _releaseType <> "update") Then _dTableApps.Rows.Add({_name.Trim, _version, _publisher.Trim, If(_regKeyString.Contains("6432"), "32", "64") & " bits"})
                            _name = Nothing
                            _installLocation = Nothing
                            _publisher = Nothing
                            _version = Nothing
                            _systemComponent = Nothing
                            _releaseType = Nothing
                        End With
                    Catch ex As Exception
                    End Try
                Next
            End Using
        Next
        With gridAplicacoes
            Try
                _dTableApps = _dTableApps.Select("", "Aplicacao").CopyToDataTable()
            Catch ex As Exception
            End Try
            .DataSource = _dTableApps
        End With           
    Catch ex As Exception
    End Try
    _regKeysFind = Nothing`
Dim_regKeysFind()作为字符串={“SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall”,
“软件\Microsoft\Windows\CurrentVersion\Uninstall”}
尝试
_dTableApps=新数据表()
使用_dTableApps
.列。添加(“APLICAO”)
.列。添加(“Versao”)
.列。添加(“制造商”)
.列。添加(“x64”)
以
对于每个_regKeyString作为_regKeysFind中的字符串
使用_regKey作为RegistryKey=Registry.LocalMachine.OpenSubKey(_regKeyString)
对于每个_regKey.GetSubKeyNames中的字符串_subkey
尝试
“获取子密钥
使用_regKey.OpenSubKey(_subkey)
Dim _name=“”,_版本为String=“”,
_installLocation=“”,\u publisher=“”,
_systemComponent=“”,_releaseType=“”
尝试
Dim_文本作为新文本框
_text.text=.GetValue(“DisplayName”).ToString
_name=\u text.text
_文本=无
特例
结束尝试
尝试
_version&=.GetValue(“DisplayVersion”).ToString
特例
结束尝试
尝试
_installLocation=.GetValue(“installLocation”).ToString
特例
结束尝试
尝试
_publisher=.GetValue(“publisher”).ToString
特例
结束尝试
尝试
_systemComponent=.GetValue(“systemComponent”).ToString
特例
结束尝试
尝试
_releaseType=.GetValue(“releaseType”).ToString.ToLower
特例
结束尝试
如果(_name.ToString“”和_systemComponent“1”和_releaseType“update”),则_dTableApps.Rows.Add({u name.Trim,_version,_publisher.Trim,如果(_regkeystering.Contains(“6432”),“32”,“64”)和“bits”})
_name=Nothing
_installLocation=无
_publisher=无
_版本=无
_systemComponent=无
_releaseType=无
以
特例
结束尝试
下一个
终端使用
下一个
有网格的
尝试
_dTableApps=\u dTableApps.Select(“,“APLICAO”).CopyToDataTable()
特例
结束尝试
.DataSource=\u dTableApps
以
特例
结束尝试
_regKeysFind=Nothing`
我能做些什么来绕过它?

谢谢你的帮助。
这样试试。
我对列表中的
子项
子项
本身添加了一个空检查,因此您可以在解析列表时验证实际查看的
注册表Ke
y。

我没有注意到两个参考文献之间有任何差异。
另外,请注意,这些图片中显示的
注册表项与同一个注册表项无关。
使用
子键
Guid查找正确的Guid。

Dim RegKeysFind() As String = {"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
                               "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"}
Dim dTableApps As DataTable = New DataTable()
With dTableApps
    .Columns.Add("Aplicacao", GetType(String))
    .Columns.Add("Versao", GetType(String))
    .Columns.Add("Fabricante", GetType(String))
    .Columns.Add("x64", GetType(String))
    .Columns.Add("RegKey", GetType(String))
End With

For Each RegKeyString As String In RegKeysFind
    Try
        Using RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey(RegKeyString, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey)
            For Each SubRegKey As String In RegKey.GetSubKeyNames
                If SubRegKey IsNot Nothing Then
                    Dim DisplayName, DisplayVersion, InstallLocation, Publisher, SystemComponent, ReleaseType As String
                    With RegKey.OpenSubKey(SubRegKey)
                        DisplayName = If(.GetValue("DisplayName") IsNot Nothing, .GetValue("DisplayName").ToString, "")
                        DisplayVersion = If(.GetValue("DisplayVersion") IsNot Nothing, .GetValue("DisplayVersion").ToString, "")
                        If DisplayVersion IsNot Nothing Then
                            Dim FirstWhiteChar As Integer = DisplayVersion.IndexOf(" "c)
                            If FirstWhiteChar > -1 Then
                                DisplayVersion = DisplayVersion.Substring(0, FirstWhiteChar)
                            End If
                        End If
                        InstallLocation = If(.GetValue("InstallLocation") IsNot Nothing, .GetValue("InstallLocation").ToString, "")
                        Publisher = If(.GetValue("Publisher") IsNot Nothing, .GetValue("Publisher").ToString, "")
                        SystemComponent = If(.GetValue("SystemComponent") IsNot Nothing, .GetValue("SystemComponent").ToString, "")
                        ReleaseType = If(.GetValue("ReleaseType") IsNot Nothing, .GetValue("ReleaseType").ToString, "")
                        If (Not String.IsNullOrEmpty(DisplayName) AndAlso (Not String.IsNullOrEmpty(SystemComponent) AndAlso (ReleaseType <> "update"))) Then
                            dTableApps.Rows.Add({DisplayName, DisplayVersion, Publisher, If(RegKeyString.Contains("WOW6432Node"), "32", "64") & " bits", SubRegKey})
                        End If
                    End With
                End If
            Next
        End Using
    Catch ex As Exception
        Console.WriteLine(ex.Message)
        Throw
    End Try
Next

dTableApps.DefaultView.Sort = dTableApps.Columns(0).ColumnName & " Asc"
gridAplicacoes.DataSource = dTableApps
Dim RegKeysFind()作为字符串={“SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall”,
“软件\Microsoft\Windows\CurrentVersion\Uninstall”}
Dim dTableApps As DataTable=新DataTable()
使用dTableApps
.Columns.Add(“APLICAO”,GetType(字符串))
.Columns.Add(“Versao”,GetType(字符串))
.Columns.Add(“Fabricante”,GetType(字符串))
.Columns.Add(“x64”,GetType(字符串))
.Columns.Add(“RegKey”,GetType(String))
以
对于每个RegKeyString作为RegKeysFind中的字符串
尝试
使用RegKey作为RegistryKey=Registry.LocalMachine.OpenSubKey(RegKeyString、RegistryKeyPermissionCheck.ReadSubTree、RegistryRights.ReadKey)
在RegKey.GetSubKeyNames中将每个子项作为字符串
如果钥匙不是空的话
Dim DisplayName、DisplayVersion、InstallLocation、Publisher、SystemComponent、ReleaseType作为字符串
使用RegKey.OpenSubKey(subkey)
DisplayName=如果(.GetValue(“DisplayName”)不是空的,.GetValue(“DisplayName”).ToString(“”)
DisplayVersion=如果(.GetValue(“DisplayVersion”)不是空的话,.GetValue(“DisplayVersion”).ToString(“”)
如果DisplayVersion不是空的,那么
Dim FirstWhiteChar作为整数=DisplayVersion.IndexOf(““c”)
如果FirstWhiteChar>-1,则
DisplayVersion=DisplayVersion.Substring(0,FirstWhiteChar)
如果结束
如果结束
 Dim _regKeysFind() As String = {"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
        "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"}
    Try
        _dTableApps = New DataTable()
        With _dTableApps
            .Columns.Add("Aplicacao", GetType(String))
            .Columns.Add("Versao", GetType(String))
            .Columns.Add("Fabricante", GetType(String))
            .Columns.Add("x64", GetType(String))
            '.Columns.Add("RegKey", GetType(String))
        End With
        For Each _regKeyString As String In _regKeysFind
            Using _regKey As RegistryKey = Registry.LocalMachine.OpenSubKey(_regKeyString)
                For Each _subRegKey As String In _regKey.GetSubKeyNames
                    If (_subRegKey IsNot Nothing) Then
                        'Get sub keys
                        With _regKey.OpenSubKey(_subRegKey)
                            Dim _name As String = "", _version As String = "", _installLocation As String = "",
                                _publisher As String = "", _systemComponent As String = "", _releaseType As String = ""
                            Try
                                _name = .GetValue("DisplayName").ToString
                                _name = _name.Split(Chr(0))(0)
                            Catch ex As Exception
                            End Try
                            Try
                                _version &= .GetValue("DisplayVersion").ToString
                                _version = _version.Split(Chr(0))(0)
                            Catch ex As Exception
                            End Try
                            Try
                                _installLocation = .GetValue("InstallLocation").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _publisher = .GetValue("Publisher").ToString
                                _publisher = _publisher.Split(Chr(0))(0)
                            Catch ex As Exception
                            End Try
                            Try
                                _systemComponent = .GetValue("SystemComponent").ToString
                            Catch ex As Exception
                            End Try
                            Try
                                _releaseType = .GetValue("ReleaseType").ToString.ToLower
                            Catch ex As Exception
                            End Try
                            If (Not String.IsNullOrEmpty(_name) AndAlso _systemComponent <> "1" AndAlso _releaseType <> "update") Then _dTableApps.Rows.Add({_name, _version, _publisher, If(_regKeyString.Contains("6432"), "32", "64") & " bits"})
                            _name = Nothing
                            _installLocation = Nothing
                            _publisher = Nothing
                            _version = Nothing
                            _systemComponent = Nothing
                            _releaseType = Nothing
                        End With
                    End If
                Next
            End Using
        Next
        With gridAplicacoes
            _dTableApps.DefaultView.Sort = _dTableApps.Columns(0).ColumnName & " Asc"
            .DataSource = _dTableApps
        End With
    Catch ex As Exception
        'MsgBox(ex.Message)
    End Try
    _regKeysFind = Nothing