Tuesday, October 11, 2011

Execute VBScript or Batch File from C#

Can never remember the correct syntax to get this working properly:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = fileName;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
var error = proc.StandardError.ReadToEnd();
proc.WaitForExit();
var output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

No comments: