在c#中调用windows脚本的方法

来源:互联网 发布:今日非农数据官网 编辑:程序博客网 时间:2024/06/01 07:35
在c#中调用windows脚本的方法

方法1:直接调用

  CODE:   System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName="wscript";
proc.StartInfo.Arguments=" hello.js";
proc.StartInfo.UseShellExecute = false;
proc.Start();

方法2:
使用MS的Windows Script Control

  CODE:    string scr = "function hello(){var WshShell = new ActiveXObject(/"WScript.Shell/");"
+"var code = /"WScript hello.js/";"
+"WshShell.Exec(code);}";
MSScriptControl.ScriptControl sc = new ScriptControl();
sc.Language = "JScript";
sc.AllowUI = true;
sc.AddCode(scr);
object[] parameters = new Object[0];
sc.Run("hello",ref parameters);
 
原创粉丝点击