public void ExecuteCommand(object command) { try { // create the ProcessStartInfo using "cmd" as the program to be run, // and "/c " as the parameters. // Incidentally, /c tells cmd that we want it to execute the command that follows, // and then exit. ProcessStartInfo procStartInfo = new ProcessStartInfo(@"cmd.exe", @" " + command); //ProcessStartInfo procStartInfo = new ProcessStartInfo(); // The following commands are needed to redirect the standard output. // This means that it will be redirected to the Process.StandardOutput StreamReader. procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; // Do not create the black window. procStartInfo.CreateNoWindow = true; //procStartInfo.FileName = "notepad.exe"; // Now we create a process, assign its ProcessStartInfo and start it Process proc = Process.Start(procStartInfo); // Get the output into a string string result = proc.StandardOutput.ReadToEnd(); // Display the command output. MessageBox.Show(result); objClsLog.WriteToLog(result, null); // Close the process proc.WaitForExit(); }
new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System)\ + @"cmd.exe", @" " + command);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)