[AccessD] \decompile
Stuart McLachlan
stuart at lexacorp.com.pg
Sat Apr 16 00:52:33 CDT 2022
On 16 Apr 2022 at 8:33, Stuart McLachlan wrote:
> Any language which can use WIn32API calls can do the same Registry
> look ups.
>
> That includes VBA if you use the appropriate function Declarations
>
Not quite that simple. Since VBA doesn't grok DWORDs and null terminated strings, the
previous code needs a bit of tweaking. This VBA function works:
Option Compare Database
Option Explicit
Const KEY_QUERY_VALUE = &H1
Const HKEY_CLASSES_ROOT = &H80000000
Const REG_SZ = 1 ' Unicode nul terminated string
Declare PtrSafe Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As LongPtr, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As LongPtr) As Long
Declare PtrSafe Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA"
_
(ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, _
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.
Declare PtrSafe Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As LongPtr) As Long
Function AccessOpener() As String
Dim lngRetVal As Long
Dim hKey As LongPtr
Dim strRet As String
lngRetVal = RegOpenKeyEx(HKEY_CLASSES_ROOT, ".accdb", 0, KEY_QUERY_VALUE,
hKey)
strRet = Space$(256) ' initialise string length for return null terminated string
lngRetVal = RegQueryValueEx(hKey, ByVal "", 0, REG_SZ, ByVal strRet, 256)
lngRetVal = RegCloseKey(hKey)
strRet = Left$(strRet, InStr(strRet, Chr$(0)) - 1) 'convert Nul termnated string to dynamic
string
strRet = strRet & "\SHELL\Open\command"
lngRetVal = RegOpenKeyEx(HKEY_CLASSES_ROOT, strRet, 0, KEY_QUERY_VALUE,
hKey)
strRet = Space$(256) ' initialise string length for null terminated string
lngRetVal = RegQueryValueEx(hKey, "", 0, REG_SZ, ByVal strRet, 256)
lngRetVal = RegCloseKey(hKey)
strRet = Left$(strRet, InStr(strRet, Chr$(0)) - 1) 'convert Nul termnated string to dynamic
string
AccessOpener = strRet
End Function
More information about the AccessD
mailing list