★★★ Please pay attention to ★★★: Source code from Microsoft's exactly the same notepad (5)

zhaozj2021-02-11  147

Type Formstate Deleted AS LONGEND TYPUBLIC FSTATE AS FormStatePublic Fstring As Stringpublic Gstring As Stringpublic SString As String

Public StartPos As IntegerPublic EndPos As IntegerPublic Tchange As BooleanType FILETIME lLowDateTime As Long lHighDateTime As LongEnd Type Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias ​​"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As LongDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongDeclare Function RegCreateKey Lib "advapi32.dll" Alias ​​"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long ) As LongDeclare Function RegDeleteKey Lib "advapi32.dll" Alias ​​"RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As LongDeclare Function RegQueryValueEx Lib "advapi32.dll" Alias ​​"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String , Byval LPRESERVED AS Long, LPTYPE AS long, BYVAL LPDATA AS STRING, LPCBDATA AS STRING, LPCBDATA As Long AS LongdeClare Function RegqueryValueexa LIB "Advapi32.dll" (Byval HKEY As Long, Byval LPVALUENAME As String, ByVal lpReserved As Long, lpType As Long, ByRef lpData As Long, lpcbData As Long) As LongDeclare Function RegSetValueEx Lib "advapi32.dll" Alias ​​"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long , ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongDeclare Function RegSetValueExA Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Long, Byval CBData As long) As longdeclare function regsetValueExb lib "advapi32.dll" alias "regsetvalueexa"

(ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Byte, ByVal cbData As Long) As LongConst ERROR_SUCCESS = 0 & Const ERROR_BADDB = 1009 & Const ERROR_BADKEY = 1010 & Const ERROR_CANTOPEN = 1011 & Const ERROR_CANTREAD = 1012 & Const ERROR_CANTWRITE = 1013 & const error_OutofMemory = 14 & const error_INVALID_PARAMETER = 87 & const error_access_denied = 5 & const error_no_more_items = 259 & const error_more_data = 234 &

Const REG_NONE = 0 & Const REG_SZ = 1 & Const REG_EXPAND_SZ = 2 & Const REG_BINARY = 3 & Const REG_DWORD = 4 & Const REG_DWORD_LITTLE_ENDIAN = 4 & Const REG_DWORD_BIG_ENDIAN = 5 & Const REG_LINK = 6 & Const REG_MULTI_SZ = 7 & Const REG_RESOURCE_LIST = 8 & Const REG_FULL_RESOURCE_DESCRIPTOR = 9 & Const REG_RESOURCE_REQUIREMENTS_LIST = 10 &

Const KEY_QUERY_VALUE = & H1 & Const KEY_SET_VALUE = & H2 & Const KEY_CREATE_SUB_KEY = & H4 & Const KEY_ENUMERATE_SUB_KEYS = & H8 & Const KEY_NOTIFY = & H10 & Const KEY_CREATE_LINK = & H20 & Const READ_CONTROL = & H20000Const WRITE_DAC = & H40000Const WRITE_OWNER = & H80000Const SYNCHRONIZE = & H100000Const STANDARD_RIGHTS_REQUIRED = & HF0000Const STANDARD_RIGHTS_READ = READ_CONTROLConst STANDARD_RIGHTS_WRITE = READ_CONTROLConst STANDARD_RIGHTS_EXECUTE = READ_CONTROLConst KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFYConst KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEYConst KEY_EXECUTE = KEY_READDim hKey As Long, MainKeyHandle As LongDim rtn As Long, lBuffer As Long, sBuffer As StringDim lBufferSize As LongDim lDataSize As LongDim ByteArray () As Byte

'This constant determins wether or not to display error messages to the'user. I have set the default value to False as an error message can and'does become irritating after a while. Turn this value to true if you want'to debug your PROGRAMMING CODE WHENE REGISTRY, AS Any Errors Will Be Displayed In A Message Box.

Const DisplayerrorSg = FALSE

Function SetDWordValue (Subkey As String, Value As String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_WRITE, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key was open successfully then rtn = RegSetValueExA (hKey, Entry, 0, REG_DWORD, Value, 4) 'write the value If Not rtn = ERROR_SUCCESS Then' if there was an error writting the value If DisplayErrorMsg = True Then 'if the user want errors displayed MsgBox ErrorMsg (rtn)' display the error End If End If rtn = RegCloseKey (hKey) 'close the key Else' if there was an error opening the key If DisplayErrorMsg = True Then 'if the user want errors displayed MsgBox ErrorMsg (rtn)' display the error End If End IfEnd IfEnd FunctionFunction GetDWORDValue (SubKey As String, Entry As String )

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_READ, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key could be opened then rtn = RegQueryValueExA (hKey, Entry, 0, REG_DWORD, lBuffer, 4) 'get the value from the registry If rtn = ERROR_SUCCESS Then' if the value could be retreived then rtn = RegCloseKey (hKey) 'close the key GetDWORDValue = lBuffer' return the value Else 'otherwise, if the value couldnt be retreived GetDWORDValue = " Error " 'return Error to the user If DisplayErrorMsg = True Then' if the user wants errors displayed MsgBox ErrorMsg (rtn) 'tell the user what was wrong End If End If Else' otherwise, if the key couldnt be opened GetDWORDValue =" Error "'Return Error to the user if displayerrormsg = true dams' if the user wants Errors Displayed MsgBox ErrorMsg (RTN)' Tell The User What Was WRONG END IF End ifend ifend functionfunction setbinaryValue (Subkey As String, Value As String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_WRITE, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key was open successfully then lDataSize = Len (Value) ReDim ByteArray (lDataSize) For i = 1 To LDataSize ByteArray (i) = ASC (Value, I, 1)) Next RTN = RegSetValueexb (HKEY, Entry, 0, Reg_binary, ByteArray (1), LDATASIZE) 'WRITE THE VALUE IF NOT RTN = Error_Success Then' IF the was an error writting the value If DisplayErrorMsg = True Then 'if the user want errors displayed MsgBox ErrorMsg (rtn)' display the error End If End If rtn = RegCloseKey (hKey) 'close the key Else' if there was an error opening The key if displayerrormsg = true dam i the user wants errors displayed msgbox errormsg (RTN) 'Display the Error End if end ifend ingnd function

Function GetBinaryValue (Subkey As String, Entry As String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_READ, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key could be opened lBufferSize = 1 rtn = RegQueryValueEx (hKey, Entry, 0, REG_BINARY, 0, lBufferSize) 'get the value from the registry sBuffer = Space (lBufferSize) rtn = RegQueryValueEx (hKey, Entry, 0, REG_BINARY, sBuffer, lBufferSize)' get the value from the registry If rtn = ERROR_SUCCESS Then 'if the value could be retreived then rtn = RegCloseKey (hKey) 'close the key GetBinaryValue = sBuffer' return the value to the user Else 'otherwise, if the value couldnt be retreived GetBinaryValue = "Error"' return Error to the user If DisplayErrorMsg = True Then 'if the User Wants To Errors Displayed MsgBox ErrorMsg (RTN) 'Display To The User End If Endiffnt Be Other VeriValue = "Error" Return Error to the user If DisplayErrorMsg = True Then 'if the user wants to errors displayed MsgBox ErrorMsg (rtn)' display the error to the user End If End IfEnd IfEnd FunctionFunction DeleteKey (Keyname As String)

Call Parsekey (Keyname, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, Keyname, 0, KEY_WRITE, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key could be opened then rtn = RegDeleteKey (hKey, Keyname) 'delete the key rtn = RegCloseKey ( HKEY) 'CLOSE THE Key End IFEND IF

END FUNCTION

Function GetMainKeyHandle (MainKeyName As String) As LongConst HKEY_CLASSES_ROOT = & H80000000Const HKEY_CURRENT_USER = & H80000001Const HKEY_LOCAL_MACHINE = & H80000002Const HKEY_USERS = & H80000003Const HKEY_PERFORMANCE_DATA = & H80000004Const HKEY_CURRENT_CONFIG = & H80000005Const HKEY_DYN_DATA = & H80000006 Select Case MainKeyName Case "HKEY_CLASSES_ROOT" GetMainKeyHandle = HKEY_CLASSES_ROOT Case "HKEY_CURRENT_USER" GetMainKeyHandle = HKEY_CURRENT_USER Case "HKEY_LOCAL_MACHINE "GetMainKeyHandle = HKEY_LOCAL_MACHINE Case" HKEY_USERS "GetMainKeyHandle = HKEY_USERS Case" HKEY_PERFORMANCE_DATA "GetMainKeyHandle = HKEY_PERFORMANCE_DATA Case" HKEY_CURRENT_CONFIG "GetMainKeyHandle = HKEY_CURRENT_CONFIG Case" HKEY_DYN_DATA "GetMainKeyHandle = HKEY_DYN_DATAEnd Select

END FUNCTION

Function ErrorMSG (LERRORCODE As Long) AS String 'IF An Error Does Accurr, And The User Wants Error Messages Displayed, Then'Display One of the Following Error Messages

Select Case Lerrorcode Case 1009, 1015 getErrorMsg = "The Registry Database Is Corrupt!" Case 2, 1010 getError = "Bad key name" case 1011 getErrorMsg = "can't Open key" Case 4, 1012 getErrorMsg = "can't Read Key "Case 5 getError =" Access to this key is denied "case 1013 getError =" can't write key "case 8, 14 getErrorMsg =" out of memory "case 87 getErrorMsg =" invalid parameter "case 234 getErrormsg =" there Is More Data Than The Buffer Has Been Allocated to Hold. "Case Else GetError =" Undefined Error Code: "& STR $ (LERRORCODE) End Selectens Function

Function GetStringValue (Subkey As String, Entry As String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_READ, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key could be opened then sBuffer = Space (255) 'make a buffer lBufferSize = Len (sBuffer) rtn = RegQueryValueEx (hKey, Entry, 0, REG_SZ, sBuffer, lBufferSize) 'get the value from the registry If rtn = ERROR_SUCCESS Then' if the value could be retreived then rtn = RegCloseKey (hKey) 'close the key sBuffer = Trim ( sBuffer) GetStringValue = Left (sBuffer, Len (sBuffer) - 1) 'return the value to the user Else' otherwise, if the value couldnt be retreived GetStringValue = "Error" 'return Error to the user If DisplayErrorMsg = True Then' if THE User Wants Errors Displayed Then MsgBox ErrorMsg (RTN) 'Tell The User What Was WRONE EndStringValue = "Error"' Return Error To The User IF DisplayErrorSg = True Then 'if The User Wants Errors Displayed The MsgBox ErrorMsg (RTN)' Tell The User What Was WRONG End If End Ifnd IFEND Function

Private Sub Parsekey (KeyName As String, KeyHandle As Long) RTN = INSTR (Keyname, "/") 'Return IF "/" is contained in the keyname

IF Left (Keyname, 5) <> "HKEY_" or Right (Keyname, 1) = "/" THE 'IF THE IS A "/" at the end of the key dam "incorrect format:" chr (10) Chr (10) Keyname 'display error to the user Exit Sub' exit the procedureElseIf rtn = 0 Then 'if the Keyname contains no "/" Keyhandle = GetMainKeyHandle (Keyname) Keyname = ""' leave Keyname blankElse 'otherwise, Keyname Contains "/" keyhandle = getMainKeyHandle (Left (Keyname, RTN - 1)) 'SEPERATE THE Keyname Keyname = Right (Keyname, Len (Keyname) - RTN) End ifend subscription CreateKey (Subkey As String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegCreateKey (MainKeyHandle, SubKey, hKey) 'create the key If rtn = ERROR_SUCCESS Then' if the key was created then rtn = RegCloseKey (hKey) 'close the key End IfEnd If

End FunctionFunction SetStringValue (Subkey As String, Value AS String)

Call Parsekey (Subkey, MAINKEYHANDLE)

If MainKeyHandle Then rtn = RegOpenKeyEx (MainKeyHandle, SubKey, 0, KEY_WRITE, hKey) 'open the key If rtn = ERROR_SUCCESS Then' if the key was open successfully then rtn = RegSetValueEx (hKey, Entry, 0, REG_SZ, ByVal Value, Len (value)) 'write the value If Not rtn = ERROR_SUCCESS Then' if there was an error writting the value If DisplayErrorMsg = True Then 'if the user wants errors displayed MsgBox ErrorMsg (rtn)' display the error End If End If rtn = RegCloseKey (hKey) 'close the key Else' if there was an error opening the key If DisplayErrorMsg = True Then 'if the user wants errors displayed MsgBox ErrorMsg (rtn)' display the error End If End IfEnd IfEnd Function

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

New Post(0)