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

丶灬走出姿态 提交于 2019-11-30 15:04:06

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.

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.

Not directly.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!