views:

404

answers:

1

Hello, I am using windows script host for some kind of installer application and I'm creating shortcuts in start menu with it. This problem came up when I switched to x64 environment (win7 ultimate x64+vs2010)

I added a reference to Windows Script Host Object Model (from c:\windows\syswow64\wshom.ocx), it generated Interop.IWshRuntimeLibrary dll.

I added 'using IWshRuntimeLibrary;' to my .cs files, but when I tried to create

WshShell sh = new WshShellClass(); 

it throws an exception:

Could not load file or assembly 'Interop.IWshRuntimeLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I assume that I would need 64-bit version of that wshom.ocx for this to work, but I don't know what should I try.

Or I'll just dump Windows Script stuff, but I need another way to create start menu shortcuts from .net application. Thanks

+2  A: 

It seems that .NET needs all assemblies to be the same 32-bit or 64-bit, and won't let you mix and match. So if you app was working in 32-bit, you should try setting the compiler options (in the project properties) to explicitly produce an "x86" (i.e., 32-bit) app (which should run on both 32-bit and 64-bit). This may be easier than tracking down a 64-bit version of the scripting host.

Note that the default compiler option seems to be "Any", which will run the .NET assembly as 64-bit when on a 64-bit OS, and 32-bit on 32-bit OSs.

Andy Jacobs
+1 Andy nice work. I hit on this same problem when upgrading a solution from VS 2008 to VS 2010 when running on x64. Even though the VS 2008 and VS 2010 versions both build to 'AnyCPU', only the VS 2008 version ran correctly. Switching the VS 2010 version to 'x86' did fix it though, thank goodness. The mystery remains why the VS 2008 version runs correctly on my x64 machine when targeting 'AnyCPU', but I'm just glad that it's working now. Thanks Andy!
Mike Rosenblum