Restlesa
سه شنبه 24 خرداد 1390, 11:44 صبح
سلام دوستان عزیز
یه سورس کار با ریجستری دارم اما نحوه کار کردن باهاشو بلد نیستم لطفا برام توضیح بدین که چه طوری می تونم توی رجیستری یه کلید با زیر کلیدهای دلخواه بسازم
کد زیر در داخل ماژول باید قرار بگیره
ممنونم
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
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 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 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, lpData As Any, ByVal cbData As Long) As Long
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4
Dim r As Long
Dim lValueType As Long
Private Sub savekey(hKey As Long, strPath As String)
Dim Keyhand&
r = RegCreateKey(hKey, strPath, Keyhand&)
r = RegCloseKey(Keyhand&)
End Sub
Private Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(hKey, strPath, Keyhand)
lResult = RegQueryValueEx(Keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(Keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function
Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
Dim Keyhand As Long
Dim r As Long
r = RegCreateKey(hKey, strPath, Keyhand)
r = RegSetValueEx(Keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(Keyhand)
End Sub
Function getdword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim r As Long
Dim Keyhand As Long
r = RegOpenKey(hKey, strPath, Keyhand)
lDataBufSize = 4
lResult = RegQueryValueEx(Keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
getdword = lBuf
End If
End If
r = RegCloseKey(Keyhand)
End Function
Private Function SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
Dim lResult As Long
Dim Keyhand As Long
Dim r As Long
r = RegCreateKey(hKey, strPath, Keyhand)
lResult = RegSetValueEx(Keyhand, strValueName, 0&, REG_DWORD, lData, 4)
r = RegCloseKey(Keyhand)
End Function
Private Function DeleteKey(ByVal hKey As Long, ByVal strKey As String)
Dim r As Long
r = RegDeleteKey(hKey, strKey)
End Function
Private Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
Dim Keyhand As Long
r = RegOpenKey(hKey, strPath, Keyhand)
r = RegDeleteValue(Keyhand, strValue)
r = RegCloseKey(Keyhand)
End Function
یه سورس کار با ریجستری دارم اما نحوه کار کردن باهاشو بلد نیستم لطفا برام توضیح بدین که چه طوری می تونم توی رجیستری یه کلید با زیر کلیدهای دلخواه بسازم
کد زیر در داخل ماژول باید قرار بگیره
ممنونم
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
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 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 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, lpData As Any, ByVal cbData As Long) As Long
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4
Dim r As Long
Dim lValueType As Long
Private Sub savekey(hKey As Long, strPath As String)
Dim Keyhand&
r = RegCreateKey(hKey, strPath, Keyhand&)
r = RegCloseKey(Keyhand&)
End Sub
Private Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(hKey, strPath, Keyhand)
lResult = RegQueryValueEx(Keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(Keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function
Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
Dim Keyhand As Long
Dim r As Long
r = RegCreateKey(hKey, strPath, Keyhand)
r = RegSetValueEx(Keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(Keyhand)
End Sub
Function getdword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim r As Long
Dim Keyhand As Long
r = RegOpenKey(hKey, strPath, Keyhand)
lDataBufSize = 4
lResult = RegQueryValueEx(Keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
getdword = lBuf
End If
End If
r = RegCloseKey(Keyhand)
End Function
Private Function SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
Dim lResult As Long
Dim Keyhand As Long
Dim r As Long
r = RegCreateKey(hKey, strPath, Keyhand)
lResult = RegSetValueEx(Keyhand, strValueName, 0&, REG_DWORD, lData, 4)
r = RegCloseKey(Keyhand)
End Function
Private Function DeleteKey(ByVal hKey As Long, ByVal strKey As String)
Dim r As Long
r = RegDeleteKey(hKey, strKey)
End Function
Private Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
Dim Keyhand As Long
r = RegOpenKey(hKey, strPath, Keyhand)
r = RegDeleteValue(Keyhand, strValue)
r = RegCloseKey(Keyhand)
End Function