在c#中调用windows脚本的方法
在程序中调用脚本,能够给应用增加很多灵活性,下面是两种调用脚本的方法
方法1:直接调用
方法2:
使用MS的Windows Script Control
方法1:直接调用
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName="wscript";
proc.StartInfo.Arguments=" hello.js";
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.StartInfo.FileName="wscript";
proc.StartInfo.Arguments=" hello.js";
proc.StartInfo.UseShellExecute = false;
proc.Start();
方法2:
使用MS的Windows Script Control
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);
+"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);