System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
Anybody know how i can do it using the API ??????Thanks in advance.
System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
Anybody know how i can do it using the API ??????Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sangeetha varadarajaraoPosted Jun 22, 2006, 4:56 AM
add the namespace System.Management using the Add Reference option and the code will work.
Try it out .
good luck,
sangitaraj
Tom ElliottPosted Jun 21, 2006, 8:46 AM
sreekanth mgPosted Jun 19, 2006, 4:59 AM
Tom ElliottPosted Jun 16, 2006, 12:45 PM
Is this something to do with my complete beginners ignorance?
Im trying to force a pc to shutdown with the following code:
System.Diagnostics.Process.Start(@"C:\WINDOWS\system32\shutdown.exe", "/f /t 00");
But the force doesnt work like i would expect it to in DOS.
Any help that anyone could give me would be great. And the simpler the better... I think i may be in slightly over my head at the moment!! But what better way to learn?!?! :)
Thanks alot.
Craig MurphyPosted Mar 22, 2006, 3:59 PM
http://www.codeproject.com/csharp/wmi.asp?df=100&forumid=7082&exp=0&select=1341200
...look for the comment "Here is the code I use to shutdown the PC using WMI:"
Shutting down a pre-XP operating system is easy enough, XP and upwards takes a little more effort.
HTH
Krishna KishorePosted Mar 21, 2006, 11:50 PM
Boss can you help me to shutdown any other system in my network...
Thank you
Craig MurphyPosted Mar 20, 2006, 8:46 AM
public enum ShutDown
{
LogOff = 0,
Shutdown = 1,
Reboot = 2,
ForcedLogOff = 4,
ForcedShutdown = 5,
ForcedReboot = 6,
PowerOff = 8,
ForcedPowerOff = 12
}
private void button2_Click(object sender, EventArgs e){
ManagementClass W32_OS = new ManagementClass("Win32_OperatingSystem"); ManagementBaseObject inParams, outParams; int result;W32_OS.Scope.Options.EnablePrivileges =
true; foreach(ManagementObject obj in W32_OS.GetInstances()){
inParams = obj.GetMethodParameters(
"Win32Shutdown");inParams[
"Flags"] = ForcedShutdown;inParams[
"Reserved"] = 0;outParams = obj.InvokeMethod(
"Win32Shutdown", inParams, null);result =
Convert.ToInt32(outParams["returnValue"]); if (result !=0) throw new Win32Exception(result);}
}
Remember to save your work before you test this code!
HTH