Welcome to the PowerOff page! PowerOff was written for Windows NT4/Windows 2000 and is a tool that you can use to remotely power off machines across the network. This is something that to my knowledge no other tool can do currently. Of course, there is the shutdown.exe utility from the Windows NT Resource Kit, but shutdown.exe can only either shutdown the target machine into the state where you see the "It is now safe to turn off your computer"-dialog or reboot the target machine. Because shutdown.exe merely wraps the InitiateSystemShutdown and AbortSystemShutdown APIs, it cannot power off a machine. The only API that can do so, is ExitWindowsEx. Unfortunately, ExitWindowsEx does not transparently work across machine boundaries, you have to do some trickery to get that done, like my PowerOff utility does. Note that on NT4 the golden code (no service pack) will not work if no user is logged in on the target machine. I tested it with Service Pack 5 and everything worked okay. Also note, that PowerOff will only work as advertised, if the target machine actually can be shut down into a power off state locally. If you cannot power off the machine in question from the normal shutdown dialog, poweroff will also fail to power off the machine. Another situation where you have to take care is the case of a machine that has been locked by the interactive user. In this case you have to power off the machine with poweroff's command line parameter /f (thanks to Uwe Gawehn for pointing this out). In the case of Windows 2000 you additionally have to force users to press Ctrl-Alt-Del before logging on (which is not the default on Windows 2000 Professional) if you want to be able to power off locked machines. You can do that by ticking the appropriate checkbox on the "Advanced" Tab of the "Users and Passwords" control panel applet.
... oh, and yes, the binary of PowerOff you can download here, is entirely UNICODE. So without any further ado:
Download PowerOff version 188.8.131.52 built on 08/14/00
How does it work?PowerOff simply interprets the first non-option argument it gets as the target host to power off and the second non-option argument argument as an optional user name. If you don't supply the user name, PowerOff will use the current user to power off the target host. Note that this user has to be a member of the local administrators group on the target machine. If you supply a user name, PowerOff will ask you the password of that user, who again has to be a member of the target hosts local administrator group. Currently, two option argument exist: The "/f" option will force a power off, which means, the standard message WM_QUERYENDSESSION and WM_ENDSESSION will not be sent to the running applications. The "/h" option will kill "hung" applications on WIN2K, even if they don't respond to the before mentioned messages. Note that using these options is mutually exclusive and can lead to a potential loss of data, because currently running applications might not be able to save their data. You have been warned, you are using poweroff at your own risk!
Here are a few command line examples:
To shut down and power off a machine named SPOCK, you simply type:
If you are logged in as a domain administrator, it is pretty easy to power off a workstation in the domain this way, you will not have to supply a user name and password, because as a domain administrator you are automatically a local administrator on the target machine.
If you are not logged in on the controlling machine with the same credentials as an administrator of machine SPOCK, you would choose an administrators user name of SPOCK, in this case "KIRK" and issue the following command:
poweroff SPOCK KIRK
PowerOff will then ask you for the password of user KIRK on SPOCK and shut down and power off SPOCK
To force a shutdown and power off you would use this command
PowerOff /f SPOCK
This will force all applications to be terminated without any warning. The obligatory pair of messages WM_QUERYENDSESSION and WM_ENDSESSION will not be sent to the running applications. Note that many applications rely on these messages to be sent in order to do cleanup work or save volatile data, but also note that this is the only way to power off a machine that has been locked by the interactive user.
To force a friendlier shutdown and power off on Win2K you would use this command
PowerOff /h SPOCK
This forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message.
Avoiding password promptingIf you are running PowerOff under a non-privileged account (for the target machine) and you need to supply a username and password (the "credentials") of an administrator on the target machine, you need not type in the password interactively each time you shut down and power off a target machine, you can instead redirect a password to avoid prompting, providing that STDIN (standard input) is redirected accordingly (which is the case if you run PowerOff from a command prompt). If PowerOff is running under a command processor, the following approaches are suitable for redirecting a password:
PowerOff SPOCK KIRK < c:\password\kirkspassword.txt
In this case, the password for user KIRK is obtained from C:\PASSWORD\kirkspassword.txt. The password must be followed by a carriage return in file C:\PASSWORD\kirkspassword.txt. On NTFS file systems, you can apply security to C:\PASSWORD\kirkspassword.txt such that only the callers of PowerOff have access to the password file or directory.
echo kirkspassword| PowerOff SPOCK KIRK
In this case, the password kirkspassword for user KIRK is piped to PowerOff. This approach is useful for batch files. Note that on NTFS file systems, the batch file executing this command should have security applied such that only the callers of PowerOff have access to the batch file. Note also that some command processors may not handle this case properly. Be sure to have no whitespace character between the password and the pipe sign (|).
Finale note: instead of the hosts name you can always use its dotted IP-address as well.
Future PlansThese depend heavily on the feedback to the current version of PowerOff. One goal is, to provide the same functionality as the shutdown.exe utility, such as the timeout, the custom message, the dialog displayed to the user prior to the shutdown and the ability to cancel an initiated poweroff.
Why I wrote this cool program......well, simply because someone in a German newsgroup complained that a power off cannot be done with the Resource Kit's shutdown utility. I first thought that this is just a flag of the shutdown APIs but it turned out that it cannot be done easily. Thus the idea was born, to write poweroff.exe as an additon to shutdown.exe in the administrator's toolchest.
What was technically challenging in writing this program?Hhm, when writing something like this you have to know a great deal about services and how to play with a remote SCM. All in all, it requires quite some experience but it took me just about one day to write this program, because it is not a real lot of code to write, once you know how it has to be done.
|Last Updated on Sunday, 28 April 2002 19:43|