我想从vbscript以同步方式执行一个.NET dll文件 - 这是可能吗?如果是,是否可以执行GAC程序集?
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?
感谢, Ofer
thanks, Ofer
推荐答案必须首先通过在AssemblyInfo.cs文件中包含ComVisible属性,使.NET程序集COM可见:
I think you must first make the .NET assembly COM-visible by including the ComVisible attribute in the AssemblyInfo.cs file:
[ComVisible(true)]在MSDN上查看此页面:为COM打包装配
See this page on MSDN: Packaging an Assembly for COM
然后在VBScript中,您可以通过相同的方式访问这些组件,即访问COM组件,即使用CreateObject或Server.CreateObject:
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")我认为GAC甚至可能是从VBScript访问它,但我没有这样做,所以我不知道。
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.
为什么要在VBScript中这样做?为什么不只是做一个.NET控制台应用程序将做你的VBScript是要做什么?因为DLL已经在.NET上,这不应该是一个问题,对吧?
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?
另一种方法是创建一个控制台EXE而不是一个DLL(或者一个包装DLL的EXE),你可以像一个正常的可执行程序一样从VBScript调用并检查返回结果。根据许多因素,这可能比维护COM代码更灵活。
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执行.NET程序集(dll)?
发布评论