void shutdown () { process commandprocess = new process (); try { commandProcess.StartInfo.FileName = "cmd.exe"; commandprocess.startinfo.useshellexecute = false; commandProcess.StartInfo.CreateNoWindow = true; Commandprocess.startinfo.redirectstandarderror = true; commandProcess.StartInfo.RedirectStandardInput = true; commandprocess.startinfo.redirectstandardoutput = true; commandprocess.start (); commandprocess.standardinput.writeline ("Shutdown /r /m 127.0.0.1 /t 200 /f "); commandprocess.standardinput.writeline ("Exit"); for (!commandprocess.hasexited; )//wait for cmd command to run complete { System.Threading.ThreaD.sleep (1); } //Error Output string tmpout = CommandProcess.StandardError.ReadToEnd (); string tmpout1 = commandprocess.standardoutput.readtoend (); } catch (exception e) { messagebox.show (e.message); } finally { if (Commandprocess != null) { commandprocess.dispose (); commandprocess = null; } } }
C # execute CMD command remote shutdown