Reading and writing to the registry using VB.NET

I made a game and I would like to keep a high score and other values ​​in the Windows registry. This is done in VB.NET. Can someone give me some sample code for an example of simple reading and writing to the registry.

thanks

+3
source share
7 answers

Spelling

Reading

Links found using Google .

+2
source

#, VB.NET. , , , . Microsoft.Win32.

+1

You can use the registry settings .getvalue and registry.setvalue. Here are a few 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.
+1
source

You must open the registry key before reading or writing. 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()
+1
source

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 the corresponding values. Data will be saved in HKEY_CURRENT_USER \ Software \ VB and VBA Program Settings \ (AppName)

0
source
SaveSetting("MyApp", "MySettings", "MyKey", myValue)

GetSetting("MyApp", "MySettings", "MyKey")

;-)

0
source

Source: https://habr.com/ru/post/1714693/


All Articles