+ 2

how to write a code in c# to shutdown the computer(windows xp)?

10th Sep 2016, 6:31 AM
shivaram
shivaram - avatar
2 Answers
+ 4
var psi = new ProcessStartInfo("shutdown","-s -t 00"); psi.CreateNoWindow = true; psi.UseShellExecute = false; Process.Start(psi);
10th Sep 2016, 9:16 AM
Zen
Zen - avatar
0
Lock the computer in C# using(Process proc = new Process()) { proc.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "rundll32.exe"); proc.StartInfo.Arguments = "user32.dll,LockWorkStation"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); } Logoff the computer in C# using(Process proc = new Process()) { proc.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "shutdown.exe"); proc.StartInfo.Arguments = "-l"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); } Restart the computer in C# using(Process proc = new Process()) { proc.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "shutdown.exe"); proc.StartInfo.Arguments = "-r -t 0"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); } Shutdown the computer in C# using(Process proc = new Process()) { proc.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "shutdown.exe"); proc.StartInfo.Arguments = "-s -t 0"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); }
30th Oct 2016, 2:59 PM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar