下面的示例说明如何检索此项的子项,以及如何将它们的名称输出到屏幕。使用 OpenSubKey 方法创建相关的特定子项的实例。然后可使用 RegistryKey 中的其他操作操作该项。
- Imports System
- Imports Microsoft.Win32
-
- Class Reg
-
- Public Shared Sub Main()
-
-
-
- Dim rk As RegistryKey = Registry.LocalMachine
-
-
- PrintKeys(rk)
- End Sub
-
- Shared Sub PrintKeys(rkey As RegistryKey)
-
-
- Dim names As String() = rkey.GetSubKeyNames()
-
- Dim icount As Integer = 0
-
- Console.WriteLine("Subkeys of " & rkey.Name)
- Console.WriteLine("-----------------------------------------------")
-
-
- Dim s As String
- For Each s In names
- Console.WriteLine(s)
-
-
-
-
- icount += 1
- If icount >= 10 Then
- Exit For
- End If
- Next s
- End Sub
- End Class
|