使用VB.NET读写注册表

问题描述 投票:3回答:5

我做了一个游戏,我想将高分和其他值存储在Windows注册表中。它是用VB.NET制作的。有人可以给我一个简单的读取和写入注册表的示例代码示例。

谢谢

vb.net registry
5个回答
2
投票

Writing

Reading

使用Google找到的链接。



1
投票

我对C#比较熟悉,但VB.NET也很简单。这是一个如何write to the registry的例子,以及如何read from the registry的另一个例子。不要忘记导入Microsoft.Win32名称空间。


1
投票

您可以使用registry.getvalue和registry.setvalue。以下是一些用于默认文件类型的示例:

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
投票

您必须在读取或写入之前打开注册表子密钥。然后你可以读或写

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()

0
投票

只是...

  Imports Microsoft.VisualBasic

  Dim s As String

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

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

用适当的值替换(AppName),(SectionName),(Key)。数据将保存在HKEY_CURRENT_USER \ Software \ VB和VBA程序设置\(AppName)中

© www.soinside.com 2019 - 2024. All rights reserved.