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

六月ゝ 毕业季﹏ 提交于 2019-12-18 16:56:35

问题


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:


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.




回答2:


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.




回答3:


Not directly.

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



来源:https://stackoverflow.com/questions/600012/is-it-possible-to-execute-a-net-assemblydll-from-vbscript

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