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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Craig MurphyRank #2,956 · 488 reputationPosted Mar 20, 2006, 3:46 AM EST
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
Krishna Kishore36 reputationPosted Mar 21, 2006, 6:50 PM EST
Boss can you help me to shutdown any other system in my network...
Thank you
Craig MurphyRank #2,956 · 488 reputationPosted Mar 22, 2006, 10:59 AM EST
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
Tom Elliott6 reputationPosted Jun 16, 2006, 8:45 AM EDT
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.
sreekanth mg33 reputationPosted Jun 19, 2006, 12:59 AM EDT
Tom Elliott6 reputationPosted Jun 21, 2006, 4:46 AM EDT
sangeetha varadarajarao2 reputationPosted Jun 22, 2006, 12:56 AM EDT
add the namespace System.Management using the Add Reference option and the code will work.
Try it out .
good luck,
sangitaraj