switch off computer
-
I did a search to see if this has already been answered, but didn't find anything (if it's already been answered, please just point me in the right direction). I need to find out how to switch off the computer at runtime, meaning from a program, not by pushing the button on the tower :) . I suppose I could just create a process using shutdown.exe with args, but that actually shuts down Windows, and I want to bypass that. I have seen it done in the past (but I don't remember what program did it). I'm hoping there's some unmanaged function call (to some dll somewhere) that will simply power off the machine with no dialogs or anything. Just beeooooop, the machine is off. Anyone?
-Daniel Typing too fast fro my owngood
-
I did a search to see if this has already been answered, but didn't find anything (if it's already been answered, please just point me in the right direction). I need to find out how to switch off the computer at runtime, meaning from a program, not by pushing the button on the tower :) . I suppose I could just create a process using shutdown.exe with args, but that actually shuts down Windows, and I want to bypass that. I have seen it done in the past (but I don't remember what program did it). I'm hoping there's some unmanaged function call (to some dll somewhere) that will simply power off the machine with no dialogs or anything. Just beeooooop, the machine is off. Anyone?
-Daniel Typing too fast fro my owngood
-
I don't see why shutdown.exe would not suit this requirement.. to be honest I don't know of another way, and if it exists I'm not sure it would be entirely safe to the machine. For no dialog, couldn't shutdown.exe -s -f work as you described?
-
I did a search to see if this has already been answered, but didn't find anything (if it's already been answered, please just point me in the right direction). I need to find out how to switch off the computer at runtime, meaning from a program, not by pushing the button on the tower :) . I suppose I could just create a process using shutdown.exe with args, but that actually shuts down Windows, and I want to bypass that. I have seen it done in the past (but I don't remember what program did it). I'm hoping there's some unmanaged function call (to some dll somewhere) that will simply power off the machine with no dialogs or anything. Just beeooooop, the machine is off. Anyone?
-Daniel Typing too fast fro my owngood
Here is an example: Rename Start Button[^]
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
I don't see why shutdown.exe would not suit this requirement.. to be honest I don't know of another way, and if it exists I'm not sure it would be entirely safe to the machine. For no dialog, couldn't shutdown.exe -s -f work as you described?
shutdown.exe would shut down Windows and then turn off the machine (depending on the arguments). However, I wish to bypass the "shut down Windows" part and just turn off the machine from the program. Yes, I know, it's not healthy. But I have a need regardless.
-Daniel Typing too fast fro my owngood
-
EliottA wrote:
to be honest I don't know of another way, and if it exists I'm not sure it would be entirely safe to the machine.
ExitWindowsEx[^] API does the job. regards
-
Here is an example: Rename Start Button[^]
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
I did a search to see if this has already been answered, but didn't find anything (if it's already been answered, please just point me in the right direction). I need to find out how to switch off the computer at runtime, meaning from a program, not by pushing the button on the tower :) . I suppose I could just create a process using shutdown.exe with args, but that actually shuts down Windows, and I want to bypass that. I have seen it done in the past (but I don't remember what program did it). I'm hoping there's some unmanaged function call (to some dll somewhere) that will simply power off the machine with no dialogs or anything. Just beeooooop, the machine is off. Anyone?
-Daniel Typing too fast fro my owngood
Looking up WMI, it appears that the following should work like I want:
ManagementClass mc = new ManagementClass("CIM_PowerSupply");
object[] methodArgs = { 6, null };//with 6 being to power off
object result = mc.InvokeMethod("SetPowerState", methodArgs);However, the program crashes with a ManagementException, saying "This method is not implemented in any class." And, Microsoft's article on the SetPowerState function says "This method is currently not implemented by WMI. To use this method, you must implement it in your own provider." It's kind of cruel to tease me with a function that doesn't actually do anything... Anyone know how it's supposed to be "implemented"?
-Daniel Typing too fast fro my owngood
-
Looking up WMI, it appears that the following should work like I want:
ManagementClass mc = new ManagementClass("CIM_PowerSupply");
object[] methodArgs = { 6, null };//with 6 being to power off
object result = mc.InvokeMethod("SetPowerState", methodArgs);However, the program crashes with a ManagementException, saying "This method is not implemented in any class." And, Microsoft's article on the SetPowerState function says "This method is currently not implemented by WMI. To use this method, you must implement it in your own provider." It's kind of cruel to tease me with a function that doesn't actually do anything... Anyone know how it's supposed to be "implemented"?
-Daniel Typing too fast fro my owngood
I guess I have some reading to do... http://msdn.microsoft.com/en-us/library/cc268228.aspx Thank you for pointing me toward System.Managment, all!
-Daniel Typing too fast fro my owngood
-
I did a search to see if this has already been answered, but didn't find anything (if it's already been answered, please just point me in the right direction). I need to find out how to switch off the computer at runtime, meaning from a program, not by pushing the button on the tower :) . I suppose I could just create a process using shutdown.exe with args, but that actually shuts down Windows, and I want to bypass that. I have seen it done in the past (but I don't remember what program did it). I'm hoping there's some unmanaged function call (to some dll somewhere) that will simply power off the machine with no dialogs or anything. Just beeooooop, the machine is off. Anyone?
-Daniel Typing too fast fro my owngood
yes shutdown sucks with shutdown.exe, specially in older windows version eg. XP here is the code i use to shut my pc down ;)
//using System.Management;
void Shutdown()
{
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"] = ShutDown.ForcedShutdown;
inParams["Reserved"] = 0;
outParams = obj.InvokeMethod("Win32Shutdown", inParams, null);
result = Convert.ToInt32(outParams["returnValue"]);
if (result != 0) throw new Win32Exception(result);
}
}
public enum ShutDown
{
LogOff = 0,
Shutdown = 1,
Reboot = 2,
ForcedLogOff = 4,
ForcedShutdown = 5,
ForcedReboot = 6,
PowerOff = 8,
ForcedPowerOff = 12
}When you test this, save all your work. There is no way to stop this thing.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
yes shutdown sucks with shutdown.exe, specially in older windows version eg. XP here is the code i use to shut my pc down ;)
//using System.Management;
void Shutdown()
{
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"] = ShutDown.ForcedShutdown;
inParams["Reserved"] = 0;
outParams = obj.InvokeMethod("Win32Shutdown", inParams, null);
result = Convert.ToInt32(outParams["returnValue"]);
if (result != 0) throw new Win32Exception(result);
}
}
public enum ShutDown
{
LogOff = 0,
Shutdown = 1,
Reboot = 2,
ForcedLogOff = 4,
ForcedShutdown = 5,
ForcedReboot = 6,
PowerOff = 8,
ForcedPowerOff = 12
}When you test this, save all your work. There is no way to stop this thing.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Thank you, Xmen, but the PowerOff and ForcedPowerOff enum values are deceptive. Yes, they do power off the computer, but they also shut down Windows before then. I was looking for a way to power off the computer without wasting time shutting down Windows (the computer just goes silent right after I double-click something.exe on my desktop). But, thanks anyway!
-Daniel Typing too fast fro my owngood