you can start process using c# by this way: using System.Diagnostics ....... Process.Start("notepad.exe"); ....... Process.Start("cmd",@"/c mysqldump --user=root --password=123 mysql > c:\db.sql -t");//useful ....... Process.Start("notepad.exe","c:\\record.txt"); ....... Process.Start("IEXPLORE.EXE","http://jnjx.126.com"); ....... Process.Start(@"C:\myFiles\MyApp.exe"); ..... and you can stop the process usingC# by this way: //you can use the function using System.Diagnostics; .......... private void KillProcess(string processName) { Process myproc= new Process(); // try { foreach(Process thisproc in Process.GetProcessesByName(processName)) { thisproc.Kill(); } } catch(Exception Exc) { MessageBox.Show(Exc.Message); } } //you can call this function like :KillProcess("iexplore.exe");
smilethat
Posts
-
process -
getting result from the cmd promptyou can do it like that: Process p = new Process(); //Fill the StartInfo of the Process----"cmd.exe" p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true;//important p.StartInfo.RedirectStandardOutput = true;//important p.StartInfo.RedirectStandardError = false;//true,the same... p.StartInfo.CreateNoWindow = true;//important string strResult; p.Start();//start the process //for example p.StandardInput.WriteLine("ping www.google.com "); p.StandardInput.WriteLine("exit");//important strResult= p.StandardOutput.ReadToEnd(); // below...you want if (strResult.IndexOf("( 0% loss )") != -1) { } else if (strResult.IndexOf("Destination host unreachable.") != -1) { } else if (strResult.IndexOf("Request timed out.") != -1) { } else if (strResult.IndexOf("Unknown host") != -1) { } else { } // if end p.Close();//close the process