Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser '返回当前用户键 Dim Key2 As Microsoft.Win32.RegistryKey Key2 = Key1.OpenSubKey("northsnow") '返回当前用户键下的northsnow键 If Key2 Is Nothing Then Key2 = Key1.CreateSubKey("northsnow") '如果键不存在就创建它 End If
2,删除注册表键 Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser '返回当前用户键 Dim Key2 As Microsoft.Win32.RegistryKey
Key2 = Key1.OpenSubKey("northsnow") '返回当前用户键下的northsnow键 If Not Key2 Is Nothing Then Key1.DeleteSubKey("northsnow") '如果键不存在就创建它 End If 3,创建或读取注册表项
Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser '返回当前用户键 Dim Key2 As Microsoft.Win32.RegistryKey Key2 = Key1.OpenSubKey("northsnow", True) '返回当前用户键下的northsnow键,如果想创建项,必须指定第二个参数为true If Key2 Is Nothing Then Key2 = Key1.CreateSubKey("northsnow") '如果键不存在就创建它 End If
'返回项值 Dim sb As New System.Text.StringBuilder sb.AppendLine(Key2.GetValue("name")) sb.AppendLine(Key2.GetValue("sex")) sb.AppendLine(Key2.GetValue("age")) MsgBox(sb.ToString)
'查验某个项是否存在 If (Key2.GetValue("name")) Is Nothing Then MsgBox("no") Else MsgBox("yes") End If