Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - 关于vbs对注册表二进制键值的处理
关于vbs对注册表二进制键值的处理
微软有个操作注册表的模块,全文如下:

'这个模块用于读和写注册表关键字“p

”不同于动词的内部注册表访问方法,它可以

'通过字符串的值来读和写任何注册表关键字选项显式

' -

'-注册表应用程序接口声明...'-

私有声明函数RegCloseKey Lib " advapi 32 "(ByVal hKey As Long)As Long

私有声明函数RegCreateKeyEx Lib " advapi 32 " Alias " RegCreateKeyExA "(ByVal hKey As Long,ByVal lpSubKey As String,ByVal Reserved As Long,ByVal lpClass As String,ByVal dwOptions As Long,ByVal samDesired As Long,ByRef lpsecurity ATTRIBUTES As SECURITY _ ATTRIBUTES,ByRef phkResult As Long,ByRef lpdwDisposition As Long) ByVal samDesired As Long、ByRef phkResult As Long)As Long

Private Declare Function RegQueryValueEx Lib " advapi 32 "别名" RegQueryValueEx a "(ByVal hKey As Long、ByVal lpValueName As String、ByRef lpType As Long、ByVal lpData As String、ByRef LPC bdata As Long)As Long

Private Declare Function RegSetValueEx Lib " advapi 32 "别名" RegSetValueEx a "(ByVal hKey As Long、by注册表美国石油学会(American Petroleum Institute)常数 ...'-' Reg数据类型...

Const REG_SZ = 1 ' Unicode空终结字符串

Const REG_EXPAND_SZ = 2 ' Unicode空终结字符串

Const REG_DWORD = 4 ' 32位数字

'注册表创建类型值...

Const REG _ OPTION _ NON _ VOLATILE = '当系统重新启动时,关键字被保留

'注册表关键字安全选项...Const READ _ CONTROL = & amp常数KEY _ QUERY _ VALUE = & ampH1常量键集值= & ampH2常量键创建子键= & ampH4常量键枚举子键= & amp常数KEY _ NOTIFY = & ampConst KEY _ CREATE _ LINK = & amph2

Const KEY _ READ = KEY _ QUERY _ VALUE+KEY _ ENUMERATE _ SUB _ KEYS+KEY _ NOTIFY+READ _ CONTROL

Const KEY _ WRITE = KEY _ SET _ VALUE+KEY _ CREATE _ SUB _ KEY+READ _ CONTROL

Const KEY _ EXECUTE = KEY _ READ

Const KEY _ ALL _ ACCESS = KEY _ QUERY _ VALUE+KEY _ SET _ VALUE+_

KEY _ CREATE _ SUB _ KEY+KEY _ ENUMERATE _ SUB _ KEYS+_

KEY _ NOTIFY+KEY _ CREATE _ LINK注册表关键字根类型...常量HKEY _ class _ ROOT = & amp;常量HKEY当前用户= & ampConst HKEY _ LOCAL _ MACHINE = & ampHKEY的Const _ USERS = & amp;常数HKEY _性能_数据= & ampH84

'返回值...Const ERROR _ NONE = Const ERROR _ bad key = 2 Const ERROR _ ACCESS _ DENIED = 8 Const ERROR _ SUCCESS = '---注册表安全属性类型...'-

私有类型SECURITY _ ATTRIBUTES

nLength Long lpSecurityDescriptor Long bInheritHandle As Boolean

End Type

'-

'示例用法- Debug。print UpodateKey(HKEY _类_根," keyname "," new value ")

'-

Public Function update key(KeyRoot为Long,KeyName为String,SubKeyName为String,SubKeyValue为String)为Boolean

Dim rc为Long '返回代码

Dim hKey As Long '处理一个注册表关键字' Dim hDepth Long '

Dim lpAttr As SECURITY _ ATTRIBUTES '注册表安全类型

lpAttr.nLength = 5 '设置安全属性为缺省值...

lpattr . lpsecuritydescriptor = '...

lpAttr.bInheritHandle = True '...'-

'-创建/打开注册表关键字...'

'-

RC = RegCreateKeyEx(KeyRoot,KeyName,_

,REG_SZ,_

REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,lpAttr,_

hKey,hDepth)'创建/打开//KeyRoot//KeyName

If(RC & lt;& gtERROR_SUCCESS)然后转到CreateKeyError '错误处理...'-

'-创建/修改关键字值...'-

If(subkey value = " ")Then subkey value = " " '要让RegSetValueEx()工作需要输入一个空格...

'创建/修改关键字值

rc = RegSetValueEx(hKey,SubKeyName,_

,REG_SZ,_

SubKeyValue,LenB(StrConv(SubKeyValue,vbfromnicode)))

If(RC & lt;& gtERROR_SUCCESS)然后转到CreateKeyError '错误处理

' -