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