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

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

感谢, 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)?

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

发布评论

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

>www.elefans.com

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