I have the following function that is supposed to return the full path to MSAccess.exe. It works fine on XP, Vista, Win 7 if they are all 32 bit but its failing on the second call to OpenSubKey and not getting anything back. I've looked in the registry for the sCLSID returned from the first call ("{73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}") and it is there along with the full hive requested:
"Software\Classes\CLSID\{73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}\LocalServer32"
I'm passing the following arguments to the function:
"Access.Application", "msaccess.exe"
Anyone have any ideas on what needs to change to get this to work with 64-bit OS?
"Software\Classes\CLSID\{73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}\LocalServer32"
I'm passing the following arguments to the function:
"Access.Application", "msaccess.exe"
Anyone have any ideas on what needs to change to get this to work with 64-bit OS?
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] GetOfficeAppPath([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sProgId [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sEXE [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Returns path of the Office application. e.g.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'GetOfficeAppPath("Access.Application", "msaccess.exe") returns[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'full path to Microsoft Access. Approach based on Q240794.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'Returns empty string if path not found in registry.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]' Enable an error handler for this procedure:[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]On[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Error[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]GoTo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ErrorHandler[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oReg [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Microsoft.Win32.RegistryKey = _[/SIZE]
[SIZE=2]Microsoft.Win32.Registry.LocalMachine[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oKey [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Microsoft.Win32.RegistryKey[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sCLSID [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sPath [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] iPos [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sKey [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' First, get the clsid from the progid from the registry key[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' HKEY_LOCAL_MACHINE\Software\Classes\<PROGID>\CLSID:[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] oKey = oReg.OpenSubKey([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Software\Classes\"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & sProgId & [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\CLSID"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2] sCLSID = oKey.GetValue([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'MsgBox("Class ID: " & sCLSID)[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' Now that we have the CLSID, locate the server path at[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' HKEY_LOCAL_MACHINE\Software\Classes\CLSID\ [/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}\LocalServer32:[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] sKey = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Software\Classes\CLSID\"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & sCLSID & [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\LocalServer32"[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#a31515] ' oKey evaluates to nothing on 64 bit after the next line[/COLOR][/SIZE]
[SIZE=2] oKey = oReg.OpenSubKey(sKey)[/SIZE]
[SIZE=2] sPath = oKey.GetValue([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] 'MsgBox("Path: " & sPath)[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] oKey.Close()[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] ' Remove any characters beyond the exe name:[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] iPos = InStr(1, sPath, sEXE, CompareMethod.Text)[/SIZE]
[SIZE=2] sPath = Microsoft.VisualBasic.Left(sPath, iPos + Len(sEXE) - 1)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Trim(sPath)[/SIZE]
[SIZE=2]ErrorHandler:[/SIZE]
[SIZE=2] MsgBox([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Error opening database."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & vbCrLf & vbCrLf & Err.Number & [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]":" [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]& Err.Description, MsgBoxStyle.Critical, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Database Error"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[/COLOR][/SIZE]