|
|
|
|
|
Author:
|
ptaylor
|
|
Views:
|
3727
|
|
|
Read from the Registry
|
|
|
Read data from the Registry
This example gets the installed path of MS Outlook
|
|
|
|
|
Dim SubString As String Dim OutlookPath as String SubString = "SOFTWARE\Microsoft\Office\10.0\Outlook\InstallRoot" OutlookPath = RegGetValue(HKEY_LOCAL_MACHINE, SubString, "Path") Declare Function RegCloseKey& Lib "advapi32.dll" (ByVal hKey&) Declare Function RegOpenKeyExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszSubKey$, dwOptions&, ByVal samDesired&, lpHKey&) Declare Function RegQueryValueExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, ByVal lpDataBuff$, nSize&) Declare Function RegQueryValueEx& Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, lpDataBuff&, nSize&) Global Const HKEY_CLASSES_ROOT = &H80000000 Global Const HKEY_CURRENT_USER = &H80000001 Global Const HKEY_LOCAL_MACHINE = &H80000002 Global Const HKEY_USERS = &H80000003 Const ERROR_SUCCESS = 0& Const REG_SZ = 1& Const REG_DWORD = 4& 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 = &H20000 Const WRITE_DAC = &H40000 Const WRITE_OWNER = &H80000 Const SYNCHRONIZE = &H100000 Const STANDARD_RIGHTS_REQUIRED = &HF0000 Const STANDARD_RIGHTS_READ = READ_CONTROL Const STANDARD_RIGHTS_WRITE = READ_CONTROL Const STANDARD_RIGHTS_EXECUTE = READ_CONTROL Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Const KEY_EXECUTE = KEY_READ Function RegGetValue$(MainKey&, SubKey$, value$) Dim sKeyType& Dim ret& Dim lpHKey& Dim lpcbData& Dim ReturnedString$ Dim ReturnedLong& If MainKey >= &H80000000 And MainKey <= &H80000006 Then ret = RegOpenKeyExA(MainKey, SubKey, 0&, KEY_READ, lpHKey) If ret <> ERROR_SUCCESS Then RegGetValue = "" Exit Function End If lpcbData = 255 ReturnedString = Space$(lpcbData) ret& = RegQueryValueExA(lpHKey, value, ByVal 0&, sKeyType, ReturnedString, lpcbData) If ret <> ERROR_SUCCESS Then RegGetValue = "" Else If sKeyType = REG_DWORD Then ret = RegQueryValueEx(lpHKey, value, ByVal 0&, sKeyType, ReturnedLong, 4) If ret = ERROR_SUCCESS Then RegGetValue = CStr(ReturnedLong) Else RegGetValue = Left$(ReturnedString, lpcbData - 1) End If End If ret = RegCloseKey(lpHKey) End If End Function
|
|
|
|
|
|
Date Added:
02/09/2007 13:05:32
|
|
|
|
|
|
|
Your Details: Not Logged In
Join Date: N/A
Last Logon: N/A
Code Snippets: N/A
Code Comments:
Forum Posts: N/A
Forum Subjects: N/A
Site Wide
Code Snippets: 32
Code Comments:
Forum Posts: 52
Forum Subjects: 24
|
|
|
|
|
|
|
|
|
|
|