是否可以从 vbscript 执行 .NET 程序集(dll)? [英] Is it possible to execute a .NET assembly(dll) from vbscript?

查看:19
本文介绍了是否可以从 vbscript 执行 .NET 程序集(dll)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以同步方式从 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?

谢谢,提供

推荐答案

我认为您必须首先通过在 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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆