是否可以从 vbscript 执行 .NET 程序集(dll)?

编程入门 行业动态 更新时间:2024-10-22 17:29:21
本文介绍了是否可以从 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)?

本文发布于:2023-11-13 14:32:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   vbscript   NET   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!