No result back on 64bit Win7 (1 Viewer)

lution

Registered User.
Local time
Today, 03:44
Joined
Mar 21, 2007
Messages
114
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?

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]
 

lution

Registered User.
Local time
Today, 03:44
Joined
Mar 21, 2007
Messages
114
Thanks Bob. I was using that to validate the version of Access on the system before I tried to open the database (had one customer wondering why my application wouldn't work when it required Access 2007 but they had Access 2003).

Looks like I've got a bigger issue than just that one since I commented out the whole version check thing and now when it gets to the point where its trying to actually open the database, I'm getting an unable to cast COM object error, unable to load type library/DLL:

Unable to cast COM object of type 'Microsoft.Office.Interop.Access.ApplicationClass' to interface type 'Microsoft.Office.Interop.Access._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

I have a Win7, 64 bit system with 64 bit OS running Office 2007 professional but it is 32 bit. Here's snippet of the code:

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] OpenDB([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sDBPath [/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] sDBPassword [/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]Boolean[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oDBEngine [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] dao.DBEngine[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oDB [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] dao.Database[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sAccPath [/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] clientPath [/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] procID [/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] oAccess [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Microsoft.Office.Interop.Access.Application[/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=#008000][SIZE=2][COLOR=#008000]'Start a new instance of Access for Automation:[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]oAccess = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Access.ApplicationClass()[/SIZE]
[SIZE=2]oDBEngine = oAccess.DBEngine[/SIZE]
[SIZE=2]oDB = oDBEngine.OpenDatabase(Name:=sDBPath, _[/SIZE]
[SIZE=2]Options:=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2]ReadOnly:=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2]Connect:=[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"MS Access;PWD="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & sDBPassword)[/SIZE]
[SIZE=2]oAccess.OpenCurrentDatabase(filepath:=sDBPath, _[/SIZE]
[SIZE=2]Exclusive:=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], bstrPassword:=sDBPassword)[/SIZE]
[SIZE=2]oDB.Close()[/SIZE]
[SIZE=2]System.Runtime.InteropServices.Marshal.ReleaseComObject(oDB)[/SIZE]
[SIZE=2]oDB = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]System.Runtime.InteropServices.Marshal.ReleaseComObject(oDBEngine)[/SIZE]
[SIZE=2]oDBEngine = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]ErrorHandler:[/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Unable to start Microsoft Access. Verify Microsoft Access is installed."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/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]

I get tossed to the ErrorHandler on the oDBEngine = oAccess.DBEngine line. I've got references to DAO & Microsoft.Office.Interop.Access (version 9.0). Its compiling fine and runs fine on my Vista & Win XP systems (both 32 bit).

Basically all this vb.net application does is verify the correct version of Access is installed, opens the Access database, and shuts itself down so I can hide the database encryption password from the users.

I've verified I only have one version of Office 2007 installed on the system. I've turned off UAC. Added the database folders to my Access trusted locations. I have a customer running Win 7, 32 bit and she's running fine so this appears to be a 64-bit issue.
 

lution

Registered User.
Local time
Today, 03:44
Joined
Mar 21, 2007
Messages
114
YAAAYYYYY found the solution which can be found in the 2nd post in this thread: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/60591b23-c601-4f1c-bd84-a26d6a977fd8


Welcome to MSDN forums!
jgalley has come up with a potential solution: Compile your project to X86 CPU. Please give it a try.​
As far as I know, OLEDB provider (generally used to connect MS Access database) is not supported in 64-bit machine.​
In order to make your 32-bit application work on a 64 bit system, the processor must be an X86.
Thus, please try the following settings:
Go to Project menu -> Properties -> Compile tab -> Select "Advanced Compile Options" -> Select "x86" instead of "AnyCPU"

Then it will compile your project for 32-bit platform, and 32-bit application can run under WOW64 mode on 64-bit machine.​
Case:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/7d92e0a8-803a-490a-94b6-691b68bc95b3

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows.
Tutorial: http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx

FAQ: Can I run 32-bit programs on a 64-bit computer?
Most programs designed for a computer running a 32-bit version of Windows will work on a computer running 64-bit versions of Windows. Notable exceptions are many antivirus programs, and some hardware drivers.​
Drivers designed for 32-bit versions of Windows do not work on computers running a 64-bit version of Windows. If you're trying to install a printer or other device that only has 32-bit drivers available, it won't work correctly on a 64-bit version of Windows. If you are unsure whether there is a 64-bit driver available for your device, go online to the Windows Vista Compatibility Center.


Best regards,
Martin Xie
Changing the compiler setting from Any to x86 solved the problem. Hope posting the solution here helps someone else from banging their head on the wall for a week.​
-Lution​
 

Users who are viewing this thread

Top Bottom