views:

504

answers:

2

Hi folks, I'm trying to get a Windows Script Component working on and x64 development machine. Works fine on x32 bit. But can't seem to get it running, I have the same problem with both JScript and VBScript.

Here's the most simple wsc component possible. All that it does it pop up "Hello" in a message box. If you save the snippit below to a file called test_lib.wsc, you'll then be able to right click and register it. It's now available as a COM Component.

<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
    description="Test Script Library"
    progid="TestScript.Lib"
    version="1.00"
    classid="{314042ea-1c42-4865-956f-08d56d1f00a8}"
>
</registration>
<public>
  <method name="Hello">
  </method>
</public>
<script language="VBScript">
<![CDATA[
Option Explicit
Function Hello()
    MsgBox("Hello.")
End Function
]]>
</script>
</component>

Next create the following sample vb-script and save it to a file called test.vbs

dim o
set o = createobject("TestScript.Lib")
o.hello()

When I run the test.vbs with cscript or wscript I always get the following. "C:\test.vbs(3, 1) Microsoft VBScript runtime error: ActiveX component can't create object: 'TestScript.Lib'"

This works perfectly fine on a 32 bit XP. Anyone got any ideas about what could be wrong?

Thanks a bunch Noel.

A: 

You need to ensure that the you run it with the 32 bit version of WScript or CScript.

By default it will run with the 64 bit version and it won't be able to load 32 bit components.

The 32bit versions of WScript and CScript are found in "%SystemRoot%\SysWOW64\

I add a new registry key with RegEdit:-

HKEY_CLASSES_ROOT\VBSFile\Shell\Open32\Command

and give it the default value of:-

"%SystemRoot%\SysWOW64\WScript.exe" "%1" %*

This gives me a Open32 entry on the context menu of a VBS file.

For CScript execution you will need to ensure the path to CSript gets the SysWOW64 folder version.

AnthonyWJones
I tried it with pure 64 bit registration 1st as all are 64 bit. Anyway I unregister the component register it with regsvr32, ran the following "C:\Windows\SysWOW64\cscript.exe c:\test.vbs" and still got the same problem.
Bigtoe
@Bigtoe: Hmm... works as you posted it on a Server 2008 x64.
AnthonyWJones
+1  A: 

Registering the wsc from the Wndows Explorer context menu, everything worked fine for me on 64bit Windows 7.

I had problems running from a 32 bit command prompt, there I had to re-register the wsc with regsvr32 from %windir%\sysWOW64, then it ran fine with both 64 and 32 bit versions of cscript.exe, when run from either 64 or 32 command prompt.

Are you sure when you're registering the wsc, that you are using the regsvr32 from the %windir%\sysWOW64 folder?

There are two versions of regsvr32, one 32 bit (in sysWOW64), one 64 bit (in system32) they're both named regsvr32.

Confused? Join the rest of us :)

Here's a good link that Highlights some gotchas on 64bit Windows: All the same yet very different

Binary Worrier
You were spot on, using the definitive version of regsvr32 from the WOW64 folder solved the problem.
Bigtoe