Private Declare Function RegQueryValueExS 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 RegSetValueExS 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
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Enum HKEY_CONSTANTS
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_DYN_DATA = &H80000006
HKEY_LOCAL_MACHINE = &H80000002
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_USERS = &H80000003
End Enum
Private Const REG_SZ = 1
Private Const REG_BT = 3
Public Function GetString(ByVal HomeKey As HKEY_CONSTANTS, ByVal KeyName As String, ByVal ValueName As String) As String
Dim hKey As Long
Dim sData As String
Dim lres As Long
Dim lDataType As Long
Dim lDlen As Long
lres = RegOpenKey(HomeKey, KeyName, hKey)
If lres <> 0 Then
GetRegString = vbNullString
Exit Function
End If
sData = String$(64, 32) & Chr$(0)
lDlen = Len(sData)
lres = RegQueryValueExS(hKey, ValueName, 0, lDataType, sData, lDlen)
If lres <> 0 Then
GetRegString = vbNullString
Exit Function
End If
If lDataType = REG_SZ Then
GetString = Left(sData, lDlen - 1)
ElseIf lDataType = REG_BT Then
GetString = Left(sData, lDlen)
Else
GetString = vbNullString
End If
lres = RegCloseKey(hKey)
End Function
Public Sub SaveString(ByVal HomeKey As HKEY_CONSTANTS, ByVal KeyName As String, ByVal ValueName As String, ByVal Data As String)
Dim hKey As Long
Dim hSubKey As Long
Dim lres As Long
lres = RegOpenKey(HomeKey, vbNullString, hKey)
lres = RegCreateKey(HomeKey, KeyName, hSubKey)
lres = RegSetValueExS(hSubKey, ValueName, 0, REG_SZ, Data + Chr$(0), Len(Data) + 1)
lres = RegCloseKey(hSubKey)
lres = RegCloseKey(hKey)
End Sub
Public Sub DeleteValue(ByVal HomeKey As HKEY_CONSTANTS, ByVal KeyName As String, ByVal ValueName As String)
Dim hKey As Long
Dim lres As Long
lres = RegOpenKey(HomeKey, KeyName, hKey)
If lres <> 0 Then Exit Sub
lres = RegDeleteValue(hKey, ValueName)
lres = RegCloseKey(hKey)
End Sub
Public Sub DeleteKey(ByVal HomeKey As HKEY_CONSTANTS, ByVal KeyName As String)
Dim lres As Long
lres = RegDeleteKey(HomeKey, KeyName)
End Sub
Public Function GetHKEY(Line As String) As HKEY_CONSTANTS
Select Case Line
Case "HKEY_CLASSES_ROOT"
GetHKEY = HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_CONFIG"
GetHKEY = HKEY_CURRENT_CONFIG
Case "HKEY_CURRENT_USER"
GetHKEY = HKEY_CURRENT_USER
Case "HKEY_DYN_DATA"
GetHKEY = HKEY_DYN_DATA
Case "HKEY_LOCAL_MACHINE"
GetHKEY = HKEY_LOCAL_MACHINE
Case "HKEY_PERFORMANCE_DATA"
GetHKEY = HKEY_PERFORMANCE_DATA
Case "HKEY_USERS"
GetHKEY = HKEY_USERS
End Select
End Function
Сейчас этот форум просматривают: AhrefsBot, Google-бот, Yandex-бот и гости: 97