我有一個應用程序,其中用戶選擇配置,我需要編寫一個函數來保存應用程序關閉時的配置,以及其他應用程序加載時加載配置,我需要使用註冊表,你可以通過給我2個小例子來幫助我如何保存和從註冊表中加載。 謝謝 Jp在vb.net保存並加載註冊表中的值
2
A
回答
6
VB中的「我的」類包含幾乎所有你需要的東西。 讀取數據:
My.Computer.Registry.LocalMachine.GetValue("mykey")
要寫入數據:
My.Computer.Registry.LocalMachine.SetValue("mykey", "myvalue")
希望它能幫助。
0
調查Registry Class。該類暴露的密鑰是
- CurrentUser - 存儲有關用戶首選項的信息。
- LocalMachine - 存儲本地機器的配置信息。
- ClassesRoot - 存儲有關類型(和類)及其屬性的信息。
- 用戶 - 存儲有關默認用戶配置的信息。
- PerformanceData - 存儲軟件組件的性能信息。
- CurrentConfig - 存儲非用戶特定的硬件信息。
瞭解使用這些密鑰很重要,因此可以爲用戶特定的實例或機器保存信息。
我不確定你使用的是什麼版本的.NET Framework。從MS
Imports Microsoft.VisualBasic
Imports System
Imports System.Security.Permissions
Imports Microsoft.Win32
Public Class RegKey
Shared Sub Main()
' Create a subkey named Test9999 under HKEY_CURRENT_USER.
Dim test9999 As RegistryKey = _
Registry.CurrentUser.CreateSubKey("Test9999")
' Create two subkeys under HKEY_CURRENT_USER\Test9999.
test9999.CreateSubKey("TestName").Close()
Dim testSettings As RegistryKey = _
test9999.CreateSubKey("TestSettings")
' Create data for the TestSettings subkey.
testSettings.SetValue("Language", "French")
testSettings.SetValue("Level", "Intermediate")
testSettings.SetValue("ID", 123)
testSettings.Close()
' Print the information from the Test9999 subkey.
Console.WriteLine("There are {0} subkeys under Test9999.", _
test9999.SubKeyCount.ToString())
For Each subKeyName As String In test9999.GetSubKeyNames()
Dim tempKey As RegistryKey = _
test9999.OpenSubKey(subKeyName)
Console.WriteLine(vbCrLf & "There are {0} values for " & _
"{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
For Each valueName As String In tempKey.GetValueNames()
Console.WriteLine("{0,-8}: {1}", valueName, _
tempKey.GetValue(valueName).ToString())
Next
Next
' Delete the ID value.
testSettings = test9999.OpenSubKey("TestSettings", True)
testSettings.DeleteValue("id")
' Verify the deletion.
Console.WriteLine(CType(testSettings.GetValue(_
"id", "ID not found."), String))
testSettings.Close()
' Delete or close the new subkey.
Console.Write(vbCrLf & "Delete newly created " & _
"registry key? (Y/N) ")
If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"C Then
Registry.CurrentUser.DeleteSubKeyTree("Test9999")
Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _
test9999.Name)
Else
Console.WriteLine(vbCrLf & "Registry key {0} closed.", _
test9999.ToString())
test9999.Close()
End If
End Sub
End Class
樣本數據
相關問題
- 1. 在VB.NET中更改註冊表值
- 2. 註冊表保存
- 3. VB.NET:保存並加載數據?
- 4. VB.net註冊表DWord
- 5. 編輯註冊表中Vb.net
- 6. 爲註冊表格中的新字段添加的值未保存在Spree中
- 7. 加載並保存列表
- 8. VB.NET保存/加載列表框
- 9. vb.net檢查是否存在註冊表子項值
- 10. 嘗試在註冊表中保存值時出錯
- 11. 在VB.NET中編輯註冊表
- 12. Wix:解析值並存儲在註冊表中
- 13. 保存文本框的值在註冊表
- 14. C#無法在LocalMachine中加載註冊表值
- 15. 加密註冊表鍵值
- 16. VB.NET讀取註冊表
- 17. VB.NET - 寫入到註冊表
- 18. 註冊表單問題VB.Net
- 19. 加載時尚未註冊的值
- 20. 使用VB.NET將用戶定義的對象保存到Windows註冊表中
- 21. 測試是否存在註冊表值
- 22. 的Django不保存註冊
- 23. 在VB.NET中將DWORD值寫入註冊表
- 24. 註冊表值沒有保存在按鍵上
- 25. 保存並加載單個值,iPhone
- 26. UISuppressionMode註冊表項不存在於註冊表中
- 27. 在Python中保存並加載Numpy Matrix
- 28. 在vb.net備份一段註冊表
- 29. Vb.net在註冊表路徑通配符
- 30. Rails註冊表格不保存