从C#运行VBScipt [英] Running VBScipt from C#

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

问题描述

大家好,

我已经在网络上浏览了,但是对于这个问题的答案,但是我尝试的一切似乎都没有用.

Hi all,

I''ve had a browse on the web but for the answer to this but everything i try doesn''t seem to work.

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.Arguments = argument;
proc.StartInfo.FileName = link;
proc.Start();



这会引发错误,提示"C:\ Program"中没有文件扩展名"
我检查了变量参数中使用的文件是否存在,并且链接为wscript.exe.

有什么想法吗?

谢谢!



This throws up an error saying "There is no file extension in "C:\Program""
I''ve checked that the file used in the variable argument exists and the link is wscript.exe.

Any ideas?

Thanks!

推荐答案

MitchG92_24,它在消息框中显示第一个自变量文本以及一条消息.


Hi MitchG92_24, this displays the first argument text along with a message in a message box


var link = "C:\\MyVbScript.vbs";
string strArgs =  "\"" + "myArg1" + "\" \"" + "myArg2" + "\""; 
var process = System.Diagnostics.Process.Start(link,strArgs);
process.WaitForExit();  // if you want to wait, otherwise, leave this out




也是我在C:\\ MyVbScript.vbs中的.vbs文件




Also my .vbs file in C:\\MyVbScript.vbs

Option Explicit
Wscript.Echo "Hello World!" + WScript.Arguments(0)


如果要传递任何文件/文件夹路径作为参数,则将参数括在双引号中,例如"C:\ Program Files \ SomeFilePath.ext"
If you are passing any file/folder path as your arguments, then enclose the arguments inside double quotes, like "C:\Program Files\SomeFilePath.ext"


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

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