从 C# 运行 vbs Sub [英] Running a vbs Sub from C#

查看:54
本文介绍了从 C# 运行 vbs Sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 c# 应用程序执行 vbs 文件中的特定子程序?

Is it possible to execute a specific sub in a vbs file from a c# application?

我已经研究过创建一个进程然后启动它,但找不到指定应执行脚本文件中的哪个特定子的方法.有没有办法指定这一点,或者有更好的方法吗?

I have looked at creating a Process and then launching it but can not find a way to specify which particular sub in the script file should be executed. Is there a way to specify this or is there a better way of doing it?

vbs 可能类似于下面的示例.我想要的是从 C# 代码中启动 test1 或 test2.

A vbs could look something like the sample below. What I want is from the C# code to launch either test1 or test2.

Public Sub test1
    msgbox "Hey1"
End Sub

Public Sub test2
    msgbox "Hey2"
End Sub

推荐答案

当使用 Visual Basic(没有 .Net)时,我使用了 脚本控制.

When using Visual Basic (without the .Net) I used the Script Control for this.

此页面包含一些文档,说明如何从老式 VB 调用它.

This page contains some documentation how to call it from good old VB.

语法看起来像这样:

  Result = ScriptControl.Run("Name", arg1, arg2, ... argn)

<小时>

编辑(阅读评论后):如果您不需要 VBScript 在您的上下文中运行(如果您不共享对象),您可以创建一个在进程外运行脚本的小型应用程序.您的主应用程序是 64 位的,辅助应用程序是 32 位的.您仍然可以传递简单的参数.


Edit (after reading comment): If you do not need the VBScript to run in your context (if you do not share objects), you could create a small application that runs the script out-of-process. Your main app is 64 bit, the helper app is 32-bit. You can still pass simple parameters.

这篇关于从 C# 运行 vbs Sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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