[dba-VB] Re: [AccessD] OT:SysCmd(acSysCmdAccessDir)

Stuart McLachlan stuart at lexacorp.com.pg
Tue Jul 1 08:19:33 CDT 2003


On 1 Jul 2003 at 8:59, Griffiths, Richard wrote:

> Hi
> 
> Does anyone have the equivalent code snipet to get the same functionality as
> SysCmd(acSysCmdAccessDir)  from within a VB app
> 

I had something in my toolbox which looked in the registry to get the 
"Shell Open" command for any registered file extension.
With a bit of tweaking, I came up with this which works for me:

Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public 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 String, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const KEY_QUERY_VALUE = &H1
Public Const REG_SZ = 1


Function AccessDir() As String
'Get the executable directory for the current version of MS Access from the registry
Dim retval As Long
Dim hKey As Long
Dim strAppName As String
Dim strExtension As String
Dim strOpenCommand As String
Dim strpathname As String

strAppName = Space$(255)
strpathname = Space$(255)

'Get the Application name for the current version of Access
strExtension = ".mdb"
retval = RegOpenKeyEx(HKEY_CLASSES_ROOT, strExtension, 0, KEY_QUERY_VALUE, hKey)
retval = RegQueryValueEx(hKey, "", 0, REG_SZ, ByVal strAppName, 256)
retval = RegCloseKey(hKey)
strAppName = Left$(strAppName, InStr(strAppName, Chr$(0)) - 1)

'Get Open Command for the Access Application
strOpenCommand = strAppName & "\shell\Open\command"
retval = RegOpenKeyEx(HKEY_CLASSES_ROOT, strOpenCommand, 0, KEY_QUERY_VALUE, hKey)
retval = RegQueryValueEx(hKey, "", 0, REG_SZ, ByVal strpathname, 256)
retval = RegCloseKey(hKey)

'Extract Application Directory from the Open Command
'First get the full executable path and filename 
'   assuming executable is quoted which it always is in my experience
strpathname = Trim$(Left$(strpathname, InStr(2, strpathname, Chr$(34))))
'Now strip off the application filename
AccessDir = Left$(strpathname, InStrRev(strpathname, "\"))
End Function

-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the dba-VB mailing list