Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute a .NET assembly(dll) from vbscript?

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

like image 442
ofer Avatar asked Mar 01 '09 16:03

ofer


3 Answers

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.

like image 110
chakrit Avatar answered Nov 14 '22 12:11

chakrit


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.

like image 44
Otávio Décio Avatar answered Nov 14 '22 12:11

Otávio Décio


Not directly.

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

like image 2
Richard Avatar answered Nov 14 '22 11:11

Richard