2012-01-13 52 views
0

我想使用cscript.exe運行vbscript文件。 我搜索了很多,但did'nt發現任何方式,而我可以用CMD與Cscript.exe將使用script.exe運行vb腳本

這是我的代碼

Process p = new Process(); 
      p.StartInfo.Arguments = @"C:\\Program Files\\VDIWorkLoad\\WorkLoadFile\\open test.vbs"; 
      p.StartInfo.FileName = "testing"; 
      p.StartInfo.UseShellExecute = false; 
      try 
      { 
       p.Start(); 
       p.WaitForExit(); 
       Console.WriteLine("Done."); 
      } 

任何想法如何,我可以使用Cscript.exe

運行我的腳本

回答

1

您應該將FileName屬性設置爲要運行的可執行文件。在你的情況下,將是cscript.exe而不是testing

p.StartInfo.Arguments = @"""C:\Program Files\VDIWorkLoad\WorkLoadFile\open test.vbs"""; 
p.StartInfo.FileName = @"C:\Windows\System32\cscript.exe"; 
+0

我愛你。你讓我的生活非常感謝:) – 2012-01-13 12:53:56

+0

你可以指導我,當我嘗試使用system.diagnostic.start(路徑)運行我的腳本;它工作正常,但當嘗試使用窗口服務執行它不工作任何想法? – 2012-01-13 13:05:24