Registry operation class

xiaoxiao2021-03-06  49

'********************************************** ** Class Name: Reginfos '** author: ronggang (ronggang@5ivb.net)' ** creation time: 2004-09-07 '** final modification: 2004-09-07' **: Implementation Registry operation '************************************************************* ***

Private Const REG_SZ As Long = 1 'String Private Const REG_BINARY As Long = 3' binary Private Const REG_DWORD As Long = 4 'value (hex, ┼ hex) Private Const HKEY_CURRENT_USER As Long = & H80000001Private Const HKEY_LOCAL_MACHINE As Long = & H80000002

'********** Registry Related Action API function defines ********** Private Declare Function RegcloseKey Lib "Advapi32.dll" (Byval HKey As Long) As longprivate Declare Function RegreateKey Lib "advapi32.dll" Alias ​​"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPrivate Declare Function RegDeleteValue Lib "advapi32.dll" Alias ​​"RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String ) As LongPrivate Declare Function RegOpenKey Lib "advapi32.dll" Alias ​​"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPrivate 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 Any, lpcbData As Long) As LongPrivate Declare Function RegSetValueEx Lib "advapi32.dll" Alias ​​"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, BYVAL RESERVED AS Long, LPDATA AS ANY, BYVAL CBDATA As Long AS LO Ng '********************************************************* *** '// Register type PUBLIC ENUM regtype string = reg_sz binary = reg_binary value = reg_dwordend enum

The value of the root node of the '// Registry PUBLIC ENUM Regkey REG_USER = HKEY_CURRENT_USER REG_MACHINE = HKEY_LOCAL_MACHINEENEEND ENUM

'********************************************** ** Function Name: getRegSettingValue '** function function: obtain the value of the registry (actual reading process)' ** parameter description: '** LNGKEY registry node value' ** Stritem registry key name "** Function returns: '** String Type' ** "" Read the registry failed (or possibly this itself is empty) '** The content of the registry key is successful "** Reference instance:' * * Strvalue = getRegSettingValue (LNGKEY, "Value") '************************************************************************************************************************************************* ********** Private Function GetRegSettingValue (ByVal lngKey As Long, _ ByVal strItem As String) As String Dim lngReturn As Long Dim uType As RegType Dim strBuffer As String Dim lngBufferSize As Long Dim intValue As Integer '// Type of this registry item LNGRETURN = RegQueryValueex (LNGKEY, STRITEM, 0, UTYPE, BYVAL 0, LNGBUFFERSIZE) '// Judgment Open Registry Key Checkup If LNGRETURN = 0 THEN' // The type of determination value is a string IF utype = string Then '// Create a string buffer strbuffer = string (lngbuffersize, chr $ (0)) '// get content lngreturn = regQueryValueex (LNGKEY, STRITEM, 0, 0, BYVAL STRBUFFER, LNGBUFFERSIZE) if lngreturn = 0 Then' // If the last one Character is ChR $ (0), deleting the last CHR $ (0) if IF INSTR (1, Strbuffer, ChR $ (0)> 0 Then getRegSettingValue = Left $ (Strbuffer, INSTR (1, Strbuffer, Chr $ (0 ))) - 1) Else getRegSettingValue = strbuffer end if End If '// The type of judgment value is binary elseif utype = binary THEN'

// Value of the registration item LNGRETURN = RegQueryValueex (LNGKEY, STRITEM, 0, 0, INTVALUE, LNGBUFFERSIZE) if lngreturn = 0 Then getRegSettingValue = INTVALUE END IF END IF End IFEND Function '******************* *************************************** ** Function Name: getRegSetting '** function function : Value of the registry '** parameter description:' ** Ukey Register the value of the table root node '** StrPath Registry Node (such as: Software / Microsoft / Windows / CurrentVersion / Run)' ** StriteM Registry Name '** Function Returns:' ** String Type '** "" Read the registry failed (it is possible to be empty)' ** Registry item content read registry success' ** Reference example: '** Strvalue = getRegSetting (reg_machine, "software / microsoft / windows / currentversion / run", app.exename)' ******************** ************************** PUBLIC FUNCTION GETREGSETTING (BYVAL STRPATH AS STRING, _ BYVAL STRITEM AS STRING) AS STRING Dim Lngreturn AS LONG '// Open Registry Regopenkey Ukey, StrPath, LNGRETURN' // Get content getRegSetting = getRegSettingValue (LNGRETURN, STRITEM) '// Close the Open Registration Item RegcloseKey LNGRETURNEEND FUNCTION

'********************************************** ** Function Name: DELREGSETTING '** Function: Delete Registry Item' ** Parameter Description: '** Ukey Register the value of the root node' ** StrPath registry node (such as: Software / Microsoft / Windows / CurrentVersion / Run) '** Stritem registration item name' ** function returns: '** No return value' ** Reference example: '** Call delRegSetting (reg_machine, "software / microsoft / windows / currentversion / run", App.Exename) '************************************************************* *** Public Sub DelregSetting (BYVAL STRPATH AS STRING, _ BYVAL STRITH AS STRING, _ BYVAL STRITEM AS STRING) DIM LNGRETURN As long '// Create a registry key, if the specified item already exists, the function will open the existing Items RegcreateKey Ukey, STRPATH, LNGRETURN '// Remove this Item RegdeleteValue Lngreturn, stritem' // Close RegcloseKey LNGRETURNEND SUB

转载请注明原文地址:https://www.9cbs.com/read-110085.html

New Post(0)