C# VB.Net-注册表项
我喜欢列举注册表项。 到目前为止,我:C# VB.Net-注册表项,c#,vb.net,registry,regedit,C#,Vb.net,Registry,Regedit,我喜欢列举注册表项。 到目前为止,我: Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\") For Each subkey In key.GetSubKeyNames ListBox1.Items.Add(subkey.ToString) Next
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\")
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
但我喜欢在函数参数中指定注册表配置单元,如下所示:
Private Function listregistry(ByVal hive As RegistryHive, ByVal path As String)
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.hive.OpenSubKey(path)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
End Function
这给了我一个错误:
“hive”不是“Microsoft.VisualBasic.MyServices.RegistryProxy”的成员
我能做些什么来解决这个问题
我能够让它工作,但这有点草率,我如何优化它:
Private Sub ListRegistryKeys(ByVal RegistryHive As String, ByVal RegistryPath As String)
Select Case RegistryHive
Case "HKEY_LOCAL_MACHINE"
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey(RegistryPath)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
Case "HKEY_CURRENT_USER"
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey(RegistryPath)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
Case "HKEY_CLASSES_ROOT"
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.ClassesRoot.OpenSubKey(RegistryPath)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
Case "HKEY_CURRENT_CONFIG"
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentConfig.OpenSubKey(RegistryPath)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
Case "HKEY_USERS"
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.Users.OpenSubKey(RegistryPath)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
End Select
End Sub
试试这个:
Private Function listregistry(ByVal hive As Microsoft.Win32.RegistryHive, ByVal path As String)
Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey(hive, Microsoft.Win32.RegistryView.Default).OpenSubKey(path)
For Each subkey In key.GetSubKeyNames
ListBox1.Items.Add(subkey.ToString)
Next
End Function
嗯,我试过你的代码…私有子列表注册表(ByVal配置单元为Microsoft.Win32.RegistryKey,ByVal路径为String)Dim键为Microsoft.Win32.RegistryKey=hive.OpenSubKey(路径)为key.GetSubKeyNames调试中的每个子键。WriteLine(subkey.ToString)下一个结束子键不起作用:/hmm。。。传递字符串并对任意值执行select case语句不是枚举。。使用Enum语句声明枚举。同时查看标志枚举。这些错误可能是什么?仅显示带蓝色下划线的错误是没有帮助的。1)“OpenBaseKey”不是“Microsoft.Win32.RegistryKey”的成员2)“RegistryView”不是“Win32”的成员。您使用的是什么版本的.NET?3.5用于此项目。我知道它适用于.NET 4.0及更高版本,但对于较旧的.NET版本是否存在工作区?因为在3.5和更早版本中,RegistryView是未知的。