Read and write to the registry with VB.NET

馋奶兔 提交于 2020-01-14 14:54:12

问题


I made a game and I would like to store the high score and other values in the windows registry. It's made in VB.NET. Could someone give me a sample code example of simple reading and writing to the registry.

Thanks


回答1:


Writing

Reading

Links found using Google.




回答2:


http://www.vbdotnetheaven.com/UploadFile/mahesh/WindowsRegistry04262005045814AM/WindowsRegistry.aspx

http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx




回答3:


I'm more comfortable with C#, but it's pretty straightforward with VB.NET too. Here's an example of how to write to the registry, and another example of how to read from the registry. Don't forget to import the Microsoft.Win32 namespace.




回答4:


You can use registry.getvalue and registry.setvalue. Here are a couple of examples used for default file types:

Registry.GetValue("HKEY_CURRENT_USER\software\classes" & "\" & fileFormatExt(i), "", "error")

Registry.SetValue("HKEY_CURRENT_USER\software\classes\" & FileType, "", appTag) ' set new value, overwrite any other, creates key if not there.



回答5:


You must open Registry sub Key before read or write. Then you can read or write

Dim regKey As RegistryKey
Dim Value As Object
regKey =My.Computer.Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\Software\VB_and_VBA_Program_Settings", True)
'Here u can read value of AppName
Value = regKey.GetValue("AppName", "Default Value")
'Or u can write the value
  value=regkey.setValue("AppName", "myApp")
regKey.Close()



回答6:


Simply...

  Imports Microsoft.VisualBasic

  Dim s As String

  SaveSetting("(AppName)", "(SectionName)", "(Key)", "(Your Value)")

  s = GetSetting("(AppName)", "(SectionName)", "(Key)", "(Default Value)")

Replace (AppName), (SectionName), (Key) with appropriate values. The data will be saved in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\(AppName)



来源:https://stackoverflow.com/questions/1250455/read-and-write-to-the-registry-with-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!