Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser '返回當(dāng)前用戶鍵 Dim Key2 As Microsoft.Win32.RegistryKey Key2 = Key1.OpenSubKey("northsnow", True) '返回當(dāng)前用戶鍵下的northsnow鍵, 如果想創(chuàng)建項(xiàng),必須指定第二個(gè)參數(shù)為true If Key2 Is Nothing Then Key2 = Key1.CreateSubKey("northsnow") '如果鍵不存在就創(chuàng)建它 End If '創(chuàng)建項(xiàng),如果不存在就創(chuàng)建,如果存在則覆蓋 Key2.SetValue("name", "塞北的雪") Key2.SetValue("sex", True) Key2.SetValue("age", 30) '返回項(xiàng)值 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) '查驗(yàn)?zāi)硞€(gè)項(xiàng)是否存在 If (Key2.GetValue("name")) Is Nothing Then MsgBox("no") Else MsgBox("yes") End If If (Key2.GetValue("name2")) Is Nothing Then MsgBox("no") Else MsgBox("yes") End If '輸出 ' 塞北的雪 'True '30 'yes 'no
|