Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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 Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, ByVal lpdwDisposition As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare 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 Long
Private Declare 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 Long
Private Declare Function RegRestoreKey Lib "advapi32.dll" Alias "RegRestoreKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal dwFlags As Long) As Long
Private Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal lpSecurityAttributes As Long) As Long
Private Declare 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 Long
Private Declare 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 Long
Private Declare 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 Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByVal PreviousState As Long, ByVal ReturnLength As Long) As Long
Private Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Private Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY
Private Const KEY_EXECUTE = KEY_READ
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Do While lReturn <> ERROR_BADDB And lReturn <> ERROR_BADKEY And lReturn <> ERROR_CANTOPEN And _
lReturn <> ERROR_CANTREAD And lReturn <> ERROR_CANTWRITE _
And lReturn <> ERROR_OUTOFMEMORY And lReturn <> ERROR_INVALID_PARAMETER _
And lReturn <> ERROR_ACCESS_DENIED And lReturn <> ERROR_NO_MORE_ITEMS
HaveSubkey = True
Exit Do
Loop
RegCloseKey mainKey
Else
HaveSubkey = False
End If
End Function
Public Function CreateValue(ByVal sPath As String, ByVal sName As String, ByVal nType As rcRegType) As Long
Select Case nType
Case rcRegType.REG_SZ: CreateValue = WriteString(sPath, sName, vbNullChar)
Case rcRegType.REG_BINARY: CreateValue = WriteBinary(sPath, sName, "")
Case rcRegType.REG_DWORD: CreateValue = WriteDWORD(sPath, sName, 0)
Case rcRegType.REG_MULTI_SZ: CreateValue = WriteString(sPath, sName, vbNullChar, REG_MULTI_SZ)
Case rcRegType.REG_EXPAND_SZ: CreateValue = WriteString(sPath, sName, vbNullChar, REG_EXPAND_SZ)
Case Else: CreateValue = 0: Exit Function
End Select
End Function
Public Function WriteString(ByVal sPath As String, ByVal sName As String, ByVal sValue As String, Optional ByVal sType As rcRegType = rcRegType.REG_SZ) As Long
Attribute WriteString.VB_Description = "Writes data of string type..."
If (KeyExists(sPath) = False) Then
If (createNoExists = True) Then
CreateKey sPath
Else
WriteString = 0
Exit Function
End If
End If
hKey = GetKeys(sPath, sKey)
If (sName = "@") Then sName = ""
If (RegOpenKeyEx(hKey, sKey, 0, KEY_WRITE, mainKey) = ERROR_SUCCESS) Then
If (RegSetValueEx(mainKey, sName, 0, sType, ByVal sValue, Len(sValue)) = ERROR_SUCCESS) Then
RegCloseKey mainKey
WriteString = mainKey
Else
WriteString = 0
End If
Else
WriteString = 0
End If
End Function
Public Function ReadString(ByVal sPath As String, ByVal sName As String, Optional sDefault As String = vbNullChar) As String
Attribute ReadString.VB_Description = "Reads data of string type..."
Dim sData As String, lDuz As Long
hKey = GetKeys(sPath, sKey)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_READ, mainKey) = ERROR_SUCCESS) Then
sData = String(255, 0)
lDuz = 255
If (RegQueryValueEx(mainKey, sName, 0, REG_SZ, sData, lDuz) = ERROR_SUCCESS) Then
RegCloseKey mainKey
sData = Left$(sData, lDuz)
If Len(sData) > 0 Then ReadString = Left$(sData, Len(sData) - 1) Else: ReadString = sDefault
Else
ReadString = sDefault
End If
Else
ReadString = sDefault
End If
End Function
Public Function WriteDWORD(ByVal sPath As String, ByVal sName As String, ByVal lValue As Long) As Long
Attribute WriteDWORD.VB_Description = "Writes data of dword type..."
If (KeyExists(sPath) = False) Then
If (createNoExists = True) Then
CreateKey sPath
Else
WriteDWORD = 0
Exit Function
End If
End If
hKey = GetKeys(sPath, sKey)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_WRITE, mainKey) = ERROR_SUCCESS) Then
If (RegSetValueExA(mainKey, sName, 0, REG_DWORD, lValue, 4) = ERROR_SUCCESS) Then
RegCloseKey mainKey
WriteDWORD = mainKey
Else
WriteDWORD = 0
End If
Else
WriteDWORD = 0
End If
End Function
Public Function ReadDWORD(ByVal sPath As String, ByVal sName As String, Optional lDefault As Double = -1) As Long
Attribute ReadDWORD.VB_Description = "Reads data of dword type..."
Dim lData As Long
hKey = GetKeys(sPath, sKey)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_READ, mainKey) = ERROR_SUCCESS) Then
If (RegQueryValueExA(mainKey, sName, 0, REG_DWORD, lData, 4) = ERROR_SUCCESS) Then
RegCloseKey mainKey
ReadDWORD = lData
Else
ReadDWORD = lDefault
End If
Else
ReadDWORD = lDefault
End If
End Function
Public Function WriteBinary(ByVal sPath As String, ByVal sName As String, _
ByVal sValue As String) As Long
Attribute WriteBinary.VB_Description = "Writes data of binary type..."
Dim L As Long, lDuz As Long, B() As Byte
If (KeyExists(sPath) = False) Then
If (createNoExists = True) Then
CreateKey sPath
Else
WriteBinary = 0
Exit Function
End If
End If
hKey = GetKeys(sPath, sKey)
sValue = StrToBin(sValue)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_WRITE, mainKey) = ERROR_SUCCESS) Then
lDuz = Len(sValue)
ReDim B(lDuz) As Byte
For L = 1 To lDuz
B(L) = Asc(Mid$(sValue, L, 1))
Next
If (lDuz = 0) Then
ReDim B(1) As Byte
B(1) = 0
End If
If (RegSetValueExB(mainKey, sName, 0, REG_BINARY, B(1), lDuz) = ERROR_SUCCESS) Then
RegCloseKey mainKey
WriteBinary = mainKey
Else
WriteBinary = 0
End If
Else
WriteBinary = 0
End If
End Function
Public Function ReadBinary(ByVal sPath As String, ByVal sName As String, Optional sDefault As String = vbNullString, Optional ByVal convertTo As convertBINType = BIN_Bin, Optional ByVal posBegin As Long = 1, Optional ByVal totalBytes As Long = 0) As Variant
Dim arrData() As Byte, lDuz As Long
Dim sData As String, strData As String, cData As Integer, nI As Long
ReDim arrData(0 To 1) As Byte
arrData(0) = 0
hKey = GetKeys(sPath, sKey)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_READ, mainKey) = ERROR_SUCCESS) Then
If totalBytes = 0 Then totalBytes = lDuz Else sData = Mid(sData, posBegin, totalBytes)
Select Case convertTo
Case BIN_Array
ReDim arrData(totalBytes - 1) As Byte
For nI = 1 To totalBytes
arrData(nI - 1) = Asc(Mid$(sData, nI, 1))
Next
ReadBinary = arrData
Case BIN_String
ReadBinary = sData
Case BIN_Dot
strData = ""
For nI = 1 To totalBytes
cData = Asc(Mid$(sData, nI, 1))
If cData < 33 Or (cData > 126 And cData < 144) Or (cData > 147 And cData < 161) Then
strData = strData & "."
Else
strData = strData & Mid$(sData, nI, 1)
End If
If nI > 0 And nI Mod 8 = 0 Then strData = strData & Chr$(13)
Next
ReadBinary = strData
Case BIN_Bin
ReadBinary = Trim$(BinToStr(sData))
End Select
Else
ReadBinary = sDefault
End If
Else
ReadBinary = sDefault
End If
End Function
Public Function KillValue(ByVal sPath As String, ByVal sName As String) As Long
Attribute KillValue.VB_Description = "Deletes value from registry..."
hKey = GetKeys(sPath, sKey)
If (RegOpenKeyEx(hKey, sKey, 0, KEY_ALL_ACCESS, mainKey) = ERROR_SUCCESS) Then
RegDeleteValue mainKey, sName
RegCloseKey mainKey
KillValue = mainKey
Else
KillValue = 0
End If
End Function
Public Function ValueExists(ByVal sPath As String, ByVal sName As String) As Boolean
Attribute ValueExists.VB_Description = "Checks if some value exists in registry"
hKey = GetKeys(sPath, sKey)
Dim sData As String
If (RegOpenKeyEx(hKey, sKey, 0, KEY_READ, mainKey) = ERROR_SUCCESS) Then
If (RegQueryValueEx(mainKey, sName, 0, 0, sData, 1) = ERROR_SUCCESS) Then
RegCloseKey mainKey
ValueExists = True
Else
ValueExists = False
End If
Else
ValueExists = False
End If
End Function
Public Function EnumValues(ByVal sPath As String, ByRef sValue() As String, ByRef sData() As Variant, Optional ByVal OnlyType As rcRegType = -1) As Long
Attribute EnumValues.VB_Description = "Enumerates all values from specified key..."
Const lengthVars = 2000
Dim rName As String
Dim rData As Long
Dim mKey As Long, rType As Long, Cnt As Long
Dim RetData As Long, retValue As Long
hKey = GetKeys(sPath, sKey)
If RegOpenKey(hKey, sKey, mKey) = ERROR_SUCCESS Then
If (UCase$(Lines(0)) <> UCase("Windows Registry Editor Version 5.00")) Then
MsgBox "Cannot import " & sRegFile & ": The specified file is not a registry file. You can import only registry files.", vbOKOnly + vbCritical, frmRegEdit.Caption