How do I determine the MS Access Install path
Asked Answered
B

3

5

I have a commandline invocation of MS Access like so:

%Programfiles%\Office11\msaccess.exe

How can I eliminate the "Office11" part so that the resulting invocation executes whatever version of MS Access that is installed? I have to run this on commandline so the option of using Start > Run dialog is not applicable.

Bainite answered 12/6, 2012 at 4:33 Comment(0)
M
5

You can read the registry to find the folder where MSACCESS.EXE is located. Here is a VBScript example.

Option Explicit
Dim MSAccPath
Dim RegKey
Dim WSHShell
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
    & "CurrentVersion\App Paths\MSACCESS.EXE\Path"
Set WSHShell = WScript.CreateObject("WScript.Shell")
MSAccPath = WSHShell.RegRead(RegKey)
WScript.Echo "MS Access Path: " & MSAccPath & "MSACCESS.EXE"
Set WSHShell = Nothing
Melissamelisse answered 12/6, 2012 at 5:36 Comment(2)
This fits well with what I was looking for. I can call the vbs file with an argument specifying the database file that I want to pass to MS Access. Thanks!Bainite
This no longer works. Since newer versions of Office install on a per user basis, there is no longer an MSACCESS.EXE key in the registry under HKEY_LOCAL_MACHINE.Source
H
6

If you want to do this using native MS Access function: SysCmd(acSysCmdAccessDir)

Head answered 3/3, 2015 at 13:50 Comment(0)
M
5

You can read the registry to find the folder where MSACCESS.EXE is located. Here is a VBScript example.

Option Explicit
Dim MSAccPath
Dim RegKey
Dim WSHShell
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
    & "CurrentVersion\App Paths\MSACCESS.EXE\Path"
Set WSHShell = WScript.CreateObject("WScript.Shell")
MSAccPath = WSHShell.RegRead(RegKey)
WScript.Echo "MS Access Path: " & MSAccPath & "MSACCESS.EXE"
Set WSHShell = Nothing
Melissamelisse answered 12/6, 2012 at 5:36 Comment(2)
This fits well with what I was looking for. I can call the vbs file with an argument specifying the database file that I want to pass to MS Access. Thanks!Bainite
This no longer works. Since newer versions of Office install on a per user basis, there is no longer an MSACCESS.EXE key in the registry under HKEY_LOCAL_MACHINE.Source
G
3

Adjusted as of April, 2022

Had been using HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\Path

but it started failing at a couple clients today 4/8/2022 I adjusted the code to check another location: HKEY_CLASSES_ROOT\Access.MDBFile\shell\New\command\

Here is the code

Private Function getMSAccessPath()

Dim WSHShell
Dim RegKey
Dim Rtn

Set WSHShell = WScript.CreateObject("WScript.Shell")

on error resume next
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\Path"
Rtn= WSHShell.RegRead(RegKey)


if err.number <> 0 then 
    RegKey = "HKEY_CLASSES_ROOT\Access.MDBFile\shell\New\command\"
    Rtn= WSHShell.RegRead(RegKey)
    Rtn = left(Rtn,instr(Rtn, "MSACCESS.EXE")-1)
    Rtn = mid(Rtn, 2)
end if
on error goto 0
getMSAccessPath = Rtn

End Function
Galiot answered 8/4, 2022 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.