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

查看:140
本文介绍了是否有可能从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?

谢谢, 奥弗

推荐答案

我想你必须首先使.NET程序集COM可见通过在AssemblyInfo.cs文件的标记有ComVisible特性的属性:

I think you must first make the .NET assembly COM-visible by including the ComVisible attribute in the AssemblyInfo.cs file:

[ComVisible(true)]

请参阅本页面MSDN上:<一href="http://msdn.microsoft.com/en-us/library/bctyca52%28VS.71%29.aspx#cpconpackagingassemblyforcomanchor1"相对=nofollow>包装的大会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 code

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天全站免登陆