加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB修改注册表

发布时间:2020-12-16 23:35:29 所属栏目:大数据 来源:网络整理
导读:把下面的内容存成.bas(模块)文件,以后只要把这个文件加入你的工程就可以 直接用这些函数了 '----------------- 'ADVAPI32 '----------------- 'functionprototypes,constants,andtypedefinitions 'forWindows32-bitRegistryAPI PublicConstHKEY_CLASSES_R

把下面的内容存成.bas(模块)文件,以后只要把这个文件加入你的工程就可以
直接用这些函数了

'-----------------
'ADVAPI32
'-----------------
'functionprototypes,constants,andtypedefinitions
'forWindows32-bitRegistryAPI

PublicConstHKEY_CLASSES_ROOT=&H80000000
PublicConstHKEY_CURRENT_USER=&H80000001
PublicConstHKEY_LOCAL_MACHINE=&H80000002
PublicConstHKEY_USERS=&H80000003
PublicConstHKEY_PERFORMANCE_DATA=&H80000004
PublicConstERROR_SUCCESS=0&

'RegistryAPIprototypes

DeclareFunctionRegCloseKeyLib"advapi32.dll"(ByValHkeyAsLong)A
sLong
DeclareFunctionRegCreateKeyLib"advapi32.dll"Alias"RegCreateKeyA"
(ByValHkeyAsLong,ByVallpSubKeyAsString,phkResultAsLong)As
Long
DeclareFunctionRegDeleteKeyLib"advapi32.dll"Alias"RegDeleteKeyA"
(ByValHkeyAsLong,ByVallpSubKeyAsString)AsLong
DeclareFunctionRegDeleteValueLib"advapi32.dll"Alias"RegDeleteVal
ueA"(ByValHkeyAsLong,ByVallpValueNameAsString)AsLong
DeclareFunctionRegOpenKeyLib"advapi32.dll"Alias"RegOpenKeyA"(By
ValHkeyAsLong,phkResultAsLong)AsLong

DeclareFunctionRegQueryValueExLib"advapi32.dll"Alias"RegQueryVal
ueExA"(ByValHkeyAsLong,ByVallpValueNameAsString,ByVallpReser
vedAsLong,lpTypeAsLong,lpDataAsAny,lpcbDataAsLong)AsLong

DeclareFunctionRegSetValueExLib"advapi32.dll"Alias"RegSetValueEx
A"(ByValHkeyAsLong,ByValReservedAs
Long,ByValdwTypeAsLong,ByValcbDataAsLong)AsL
ong
PublicConstREG_SZ=1'Unicodenulterminat
edstring
PublicConstREG_DWORD=4'32-bitnumber

PublicSubSaveKey(HkeyAsLong,strPathAsString)
Dimkeyhand&
r=RegCreateKey(Hkey,strPath,keyhand&)
r=RegCloseKey(keyhand&)
EndSub

PublicFunctionGetString(HkeyAsLong,strPathAsString,strValueAs
String)AsString

DimkeyhandAsLong
DimdatatypeAsLong
DimlResultAsLong
DimstrBufAsString
DimlDataBufSizeAsLong
DimintZeroPosAsInteger
r=RegOpenKey(Hkey,keyhand)
lResult=RegQueryValueEx(keyhand,strValue,0&,lValueType,ByVal0&,
lDataBufSize)
IflValueType=REG_SZThen
strBuf=String(lDataBufSize,"")
lResult=RegQueryValueEx(keyhand,ByValstrBuf,
lDataBufSize)
IflResult=ERROR_SUCCESSThen
intZeroPos=InStr(strBuf,Chr$(0))
IfintZeroPos>0Then
GetString=Left$(strBuf,intZeroPos-1)
Else
GetString=strBuf
EndIf
EndIf
EndIf
EndFunction


PublicSubSaveString(HkeyAsLong,strValueAsStr
ing,strdataAsString)
DimkeyhandAsLong
DimrAsLong
r=RegCreateKey(Hkey,keyhand)
r=RegSetValueEx(keyhand,REG_SZ,ByValstrdata,Len(str
data))
r=RegCloseKey(keyhand)
EndSub


FunctionGetDword(ByValHkeyAsLong,ByValstrPathAsString,ByVals
trValueNameAsString)AsLong
DimlResultAsLong
DimlValueTypeAsLong
DimlBufAsLong
DimlDataBufSizeAsLong
DimrAsLong
DimkeyhandAsLong

r=RegOpenKey(Hkey,keyhand)

'Getlength/datatype
lDataBufSize=4

lResult=RegQueryValueEx(keyhand,strValueName,lBuf,
lDataBufSize)

IflResult=ERROR_SUCCESSThen
IflValueType=REG_DWORDThen
GetDword=lBuf
EndIf
'Else
'Callerrlog("GetDWORD-"&strPath,False)
EndIf

r=RegCloseKey(keyhand)

EndFunction

FunctionSaveDword(ByValHkeyAsLong,ByVal
strValueNameAsString,ByVallDataAsLong)
DimlResultAsLong
DimkeyhandAsLong
DimrAsLong
r=RegCreateKey(Hkey,keyhand)
lResult=RegSetValueEx(keyhand,REG_DWORD,lDat
a,4)
'IflResult<>error_successThenCallerrlog("SetDWORD",False)
r=RegCloseKey(keyhand)
EndFunction

PublicFunctionDeleteKey(ByValHkeyAsLong,ByValstrKeyAsString)

DimrAsLong
r=RegDeleteKey(Hkey,strKey)
EndFunction

PublicFunctionDeleteValue(ByValHkeyAsLong,ByValstrPathAsStrin
g,ByValstrValueAsString)
DimkeyhandAsLong
r=RegOpenKey(Hkey,keyhand)
r=RegDeleteValue(keyhand,strValue)
r=RegCloseKey(keyhand)
EndFunction

--
DimfishyAsFriend

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读