Posted by: temanggunglinux | November 28, 2008

Read Value Registry

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 RegCloseKey Lib “advapi32.dll” (ByVal hKey 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 ‘ Note that if you declare the lpData parameter as String, you must pass it By Value.

Private Const REG_DWORD = 4
Private Const REG_BINARY = 3
Private Const REG_EXPAND_SZ = 2
Private Const REG_MULTI_SZ = 7
Private Const REG_SZ = 1
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_CURRENT_CONFIG = &H80000005

Private Function ReadRegistryValue(ByVal hKey As Long, ByVal strSubKey As String, ByVal strValueName As String)

Dim ret As Long
Dim hasil As String * 255, bufsize As Long
Dim kembalian As Long

On Error GoTo salah
RegCreateKey hKey, strSubKey, ret
RegQueryValueEx ret, strValueName, 0, typevalue, ByVal 0, bufsize
Select Case typevalue
Case REG_SZ
RegQueryValueEx ret, strValueName, 0, typevalue, ByVal hasil, bufsize
ReadRegistryValue = Left$(hasil, InStr(hasil, Chr$(0)) – 1)
Case REG_EXPAND_SZ
RegQueryValueEx ret, strValueName, 0, typevalue, ByVal hasil, bufsize
ReadRegistryValue = Left$(hasil, InStr(hasil, Chr$(0)) – 1)
Case REG_DWORD
Dim hasildword As Long
RegQueryValueEx ret, strValueName, 0, typevalue, hasildword, bufsize
ReadRegistryValue = hasildword
Case REG_BINARY
Dim hasilbinary As Integer
RegQueryValueEx ret, strValueName, 0, typevalue, hasilbinary, bufsize
ReadRegistryValue = hasilbinary
End Select
MsgBox ReadRegistryValue, vbInformation, “Read Value”
RegCloseKey ret
Exit Function

salah:
MsgBox Err.Description, vbInformation, “Error Number: ” & Err.Number
End Function

Private Sub Form_Load()

ReadRegistryValue HKEY_CURRENT_USER, “Control Panel\Desktop”, “ConvertedWallpaper”

End Sub

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.