tags:

views:

1375

answers:

3

I'd like to execute a .NET dll file from vbscript in a synchronous way - is this possible? if yes, is it possible to execute a GAC assembly?

thanks, Ofer

+1  A: 

VBScript can only execute code from COM objects, so you would need to create a COM wrapper for your .NET code and then you should be able to call your .net code.

Otávio Décio
+1  A: 

Not directly.

If the .NET assembly was exposed as a COM component, then it could be.

Richard
+13  A: 

I think you must first make the .NET assembly COM-visible by including the ComVisible attribute in the AssemblyInfo.cs file:

[ComVisible(true)]

See this page on MSDN: Packaging an Assembly for COM

And then in VBScript you can access those components by the same means you access COM components, i.e. using CreateObject or Server.CreateObject as in:

Set testObj = CreateObject("MyNamespace.MyType")

I think GAC might even be mandatory to access it from VBScript but I havn't done it this way around so I'm not sure.

Why would you want to do that in VBScript? Why not just make a .NET console application that would do what your VBScript was meant to do? Since the DLL is already on .NET, that shouldn't be a problem, right?


EDIT: Another way to do this might be to create a console EXE instead of a DLL (or an EXE that wraps up a DLL) that you can call from VBScript like a normal executable program and examine return results. Depending on many factors, this might be more flexible than maintain COM code.

chakrit
As usual im forced to to that :-)There is an existing project written in vbscript that needs to be extended. the extension can not be done using vbscript.
ofer
@ofer duh... I know the pain of maintain legacy code in a legacy language.
chakrit