vb点虐 查找注册表 vbs 读注册表键值

VB.NET中怎么读取注册表键值

利用VB.NET访问注册表

创新互联建站服务项目包括龙子湖网站建设、龙子湖网站制作、龙子湖网页制作以及龙子湖网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,龙子湖网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到龙子湖省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

译者注:访问注册表的例子比较多,然而通过VB.NET访问注册表的例子并不多,本文翻译了一篇MSDN上的利用VB.NET存取注册表的例子,挺详细也挺全面的。

(

)

Cat

Francis

Visual

Studio

Team

Microsoft

Corporation

April

2002

摘要:这篇文章描述了利用VB.NET内置函数DeleteSetting,

GetAllSettings,

GetSetting

SaveSetting,以及通用语言运行时的两个类Registry

RegistryKey来存取注册表的实例,详述了所需的权限,解释了何时利用注册表编辑器,并向你展示了如何利用程序从注册表中动态的读取数据及如何写入数据。

引言

当用VB.NET进行编程时,你可能会选择用VB.NET或.NET框架中的Registry类中的函数来访问注册表。虽然大多数情况下VB.NET的内置函数足够用了,然而某些情况下你仍然需要.NET框架类来解决问题。

注册表不仅存储了本地机上一些程序的信息,还保存了操作系统的信息。操作注册表可能会有危险。因此编程时必须谨慎的查看代码,确保程序对所运行的机器上的安全不会构成威胁。

注册表入口点包括两部分:键名和键值。入口点是存储在系统中的键和子键,类似于文件系统中的目录和子目录。

必备知识

要想读懂本文需要有如下的必备知识:

1、熟悉上一个版本的Visual

Basic。

2、注册表设计和利用的知识。

3、理解访问注册表的安全含义。

用VB.NET内置函数访问注册表

VB.NET提供了四个访问注册表的函数,为了使用它们,首先必须有读写权限。任何运行在全信任模式下的代码都必须有访问注册表的必要的权限。可以查看RegistryPermission类从而

vb点虐 读取注册表

Sub Button1Click(sender As Object, e As EventArgs)

'HKEY_CLASSES_ROOT\.doc

Dim Root1 As RegistryKey = Registry.ClassesRoot

 '打开"SYSTEM"子健

Dim key1 As RegistryKey = Root1.OpenSubKey ( ".doc" ,true )

 '打开".doc"子健

textBox1.Text  =key1.GetValue(String.Empty)

End Sub

vb点虐 如何判断注册表是否存在?

Dim a As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run")

If a.GetValue("查看数据.exe", "null").ToString = "null" Then

我自己写的一段代码,用getvalue函数,如果开机自动运行的注册表目录中不存在查看数据。exe这条数据,则返回null,不知道你能不能用上。

VB点虐 2010 操作注册表

的完整路径写在HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

就可以自启动了。

以下是我前一段时间写的防u盘自动运行的程序,里面可以找到如何操作注册表。

Option Explicit

Global Const REG_SZ As Long = 1

Global Const REG_DWORD As Long = 4

Global Const HKEY_CLASSES_ROOT = H80000000

Global Const HKEY_CURRENT_USER = H80000001

Global Const HKEY_LOCAL_MACHINE = H80000002

Global Const HKEY_USERS = H80000003

Global Const ERROR_NONE = 0

Global Const ERROR_BADDB = 1

Global Const ERROR_BADKEY = 2

Global Const ERROR_CANTOPEN = 3

Global Const ERROR_CANTREAD = 4

Global Const ERROR_CANTWRITE = 5

Global Const ERROR_OUTOFMEMORY = 6

Global Const ERROR_INVALID_PARAMETER = 7

Global Const ERROR_ACCESS_DENIED = 8

Global Const ERROR_INVALID_PARAMETERS = 87

Global Const ERROR_NO_MORE_ITEMS = 259

Global Const KEY_ALL_ACCESS = H3F

Global Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long

Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long

Private Sub cmdAbout_Click()

MsgBox "作者wolfccb不对本软件可能造成的任何错误或损失负责,请自行承担使用风险。", vbInformation, "About"

End Sub

Private Sub cmdDefault_Click()

Check0.Value = 1

Check1.Value = 0

Check2.Value = 1

Check3.Value = 0

Check4.Value = 1

Check5.Value = 0

Check6.Value = 0

End Sub

Private Sub cmdExit_Click()

Unload Me

End Sub

Private Sub cmdRecommend_Click()

Check0.Value = 1

Check1.Value = 1

Check2.Value = 1

Check3.Value = 1

Check4.Value = 1

Check5.Value = 0

Check6.Value = 1

End Sub

Private Sub cmdSet_Click()

Dim hkey As Long

Dim lvalue As Long

Dim cddata As Long

Dim retval As Long

lvalue = GetValue

retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0, KEY_ALL_ACCESS, hkey)

retval = RegSetValueEx(hkey, "NoDriveTypeAutoRun", 0, REG_DWORD, lvalue, 4)

RegCloseKey hkey

If retval = 0 Then

MsgBox "设置已保存。", vbInformation, "提示"

Else

MsgBox "保存失败,错误代码:" + CStr(retval), vbExclamation, "错误"

End If

End Sub

Private Sub Form_Load()

Dim hkey As Long

Dim lvalue As Long

Dim cddata As Long

Dim retval As Long

retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0, KEY_ALL_ACCESS, hkey)

If retval 0 Then

MsgBox "打开注册表失败,错误代码:" + CStr(retval), vbExclamation, "错误"

End If

retval = RegQueryValueEx(hkey, "NoDriveTypeAutoRun", 0, REG_DWORD, lvalue, 4)

RegCloseKey hkey

If retval 0 Then

MsgBox "读取注册表失败,错误代码:" + CStr(retval), vbExclamation, "错误"

End If

ShowCheck (lvalue)

End Sub

Private Sub ShowCheck(lvalue As Long)

Check0.Value = lvalue Mod 2

lvalue = (lvalue - Check0.Value) / 2

Check1.Value = lvalue Mod 2

lvalue = (lvalue - Check1.Value) / 2

Check2.Value = lvalue Mod 2

lvalue = (lvalue - Check2.Value) / 2

Check3.Value = lvalue Mod 2

lvalue = (lvalue - Check3.Value) / 2

Check4.Value = lvalue Mod 2

lvalue = (lvalue - Check4.Value) / 2

Check5.Value = lvalue Mod 2

lvalue = (lvalue - Check5.Value) / 2

Check6.Value = lvalue Mod 2

End Sub

Private Function GetValue() As Long

GetValue = Check0.Value + Check1.Value * 2 + Check2.Value * 4 + Check3.Value * 8 + Check4.Value * 16 + Check5.Value * 32 + Check6.Value * 64 + 128

End Function

以上。

饿的老狼


当前题目:vb点虐 查找注册表 vbs 读注册表键值
路径分享:http://scyanting.com/article/ddeisos.html