使用 VB.NET 在“HKEY_LOCAL_MACHINE\Software"中保存并获取注册表值 [英] Save and Get a Registry Value in 'HKEY_LOCAL_MACHINE\Software' using VB.NET

查看:33
本文介绍了使用 VB.NET 在“HKEY_LOCAL_MACHINE\Software"中保存并获取注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 VB.NET 项目中,我想在HKEY_LOCAL_MACHINE\Software"中保存并获取注册表值,但我只能在HKEY_LOCAL_MACHINE"中保存和获取它,而不能在软件中获取它.

In my VB.NET project I want to save and get a registry value in "HKEY_LOCAL_MACHINE\Software" but I am only able to save and get it in "HKEY_LOCAL_MACHINE" but not software.

这是我的代码:

用于设置值

My.Computer.Registry.LocalMachine.SetValue("Study", "1")

为了获取价值

Dim RegistryCheck As String = My.Computer.Registry.LocalMachine.GetValue("Study")

推荐答案

您必须验证您是否具有从 HKEY_LOCAL_MACHINE 写入(以及读取)的权限.如果您无法获得所需的权限(这很有可能),请选择 HKEY_CURRENT_USER (My.Computer.Registry.CurrentUser).无论如何,您必须指定所需的权限类型:读取/读取写入.请参阅 OpenSubKey() 方法的重载.其中两个让您指定这些要求.如果/当您被授予权限时,创建子项 (CreateSubKey()),然后在其中设置一个键值(使用 SetValue()),使用 RegistryValueKind 指定一个值类型.

You have to verify if you have the permission to write (and also read) from HKEY_LOCAL_MACHINE. If you can't get the required permissions (which is quite possible), opt for HKEY_CURRENT_USER (My.Computer.Registry.CurrentUser). Anyway, you have to specify what kind of permissions you're requiring: Read/ReadWrite. See the overloads of the OpenSubKey() method. Two of them let's you specify these requirements. If/When you are granted the permission, create the subkey (CreateSubKey()) and then set a key value inside it (with SetValue()), specifying a value type with RegistryValueKind.

这篇关于使用 VB.NET 在“HKEY_LOCAL_MACHINE\Software"中保存并获取注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆