2012-01-13 50 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