VB修改注册表

把下面的内容存成.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

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...