Doggie Posted May 22, 2003 Share Posted May 22, 2003 well its simple and heres the code Visual BasicIt only executes the uninstallmodule code(note: this has lots of registry features for yas )Option ExplicitGlobal infoGlobal gGlobal allcharactersGlobal molestate()Type FILETIME lLowDateTime As Long lHighDateTime As LongEnd TypeDeclare 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 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 ByteConst DisplayErrorMsg = FalseFunction SetDWORDValue(SubKey As String, Entry As String, Value As Long)Call ParseKey(SubKey, MainKeyHandle)If MainKeyHandle Then rtn = RegOpenKeyEx(MainKeyHandle, SubKey, 0, KEY_WRITE, hKey) 'open the key If rtn = ERROR_SUCCESS Then rtn = RegSetValueExA(hKey, Entry, 0, REG_DWORD, Value, 4) If Not rtn = ERROR_SUCCESS Then If DisplayErrorMsg = True Then MsgBox ErrorMsg(rtn) 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 Then '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, Entry As String, Value As String)Dim iCall 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(Mid$(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 Then 'if the user wants errors displayed MsgBox ErrorMsg(rtn) 'display the error End If End IfEnd IfEnd FunctionFunction 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 the error to the user End If End If Else 'otherwise, if the key couldnt be opened GetBinaryValue = "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 IfEnd FunctionFunction 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 SelectEnd FunctionFunction ErrorMsg(lErrorCode As Long) As String Dim GetErrorMsg'If an error does accurr, and the user wants error messages displayed, then'display one of the following error messagesSelect Case lErrorCode Case 1009, 1015 GetErrorMsg = "The Registry Database is corrupt!" Case 2, 1010 GetErrorMsg = "Bad Key Name" Case 1011 GetErrorMsg = "Can't Open Key" Case 4, 1012 GetErrorMsg = "Can't Read Key" Case 5 GetErrorMsg = "Access to this key is denied" Case 1013 GetErrorMsg = "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 GetErrorMsg = "Undefined Error Code: " & Str$(lErrorCode)End SelectEnd FunctionFunction 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 wrong End If End If Else 'otherwise, if the key couldnt be opened 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 wrong End If End IfEnd IfEnd FunctionPrivate Sub ParseKey(KeyName As String, Keyhandle As Long) rtn = InStr(KeyName, "\") 'return if "\" is contained in the KeynameIf Left(KeyName, 5) <> "HKEY_" Or Right(KeyName, 1) = "\" Then 'if the is a "\" at the end of the Keyname then MsgBox "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 SubFunction 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 IfEnd FunctionFunction SetStringValue(SubKey As String, Entry 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 Functionand this is the function to execute Dim msKey msKey = GetStringValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MessengerService", "RollbackParameters") Shell "RunDll32.EXE" & " " & msKey Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now