using Windows Script Host

Axarydax picture Axarydax · Feb 18, 2010 · Viewed 9.6k times · Source

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.

Answer

Andy Jacobs picture Andy Jacobs · Feb 19, 2010

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.