how do i restart computer programatically in .NET 2.0 / VS 2005
Printable View
how do i restart computer programatically in .NET 2.0 / VS 2005
Multiple examples already posted on the forum. Execute shutdown.exe from the system32 folder with the appropriate commandline arguments or use the ExitWindowsEx API.
i have already used the Shutdown.exe code
System.Diagnostics.Process.Start("Shutdown", "/r")
but it takes 30 seconds before proceeding, i want it to be direct
can u pls give me the example of the ExitWindow API that u were referring to
Shutdown.exe will NOT take 30 seconds if you pass it the correct commandline parameters. Read the Windows help topic for it and that explains all the commandline parameters, or else do the standard for Windows commandline apps that require commandline parameters and use the command prompt itself to get help. If you enter "shutdown" into a command prompt with no commandline parameters or with the "/?" switch it will tell you what all the accepted commandline parameters are.
As for ExitWindowsEx, as I said, there are already multiple examples posted on the forum so I'm not going to add another.
You can also simply crash it using some handy critical service. It'd take less than a second so you have a choice between a speedy restart or a safe recovery.
you can use System.Diagnostics.Process.Start("Shutdown", "/r /t 00") which will set the timer to 00 and instant restart.