cmd Process
public bool CmdRun(Command cmd) { var proc = new System.Diagnostics.Process { EnableRaisingEvents = false, StartInfo = {FileName = cmd.FileName, Arguments = cmd.Argument} }; proc.Start(); proc.WaitForExit(); return MessageBox.Show("You have just visited www.microsoft.com") == DialogResult.OK; }
PS need powershell sdk >=2.0
public bool CmdTest(string cmd) { using (PowerShell powershell = PowerShell.Create().AddCommand(cmd)) { Console.WriteLine(cmd + " RUN"); Console.WriteLine("--------------------------------"); // Invoke the command synchronously and display the
// ProcessName and HandleCount properties of the // objects that are returned. foreach (PSObject result in powershell.Invoke()) { Console.WriteLine("{0}", result); } } return false; }