Is shutdown.exe necessary to shutdown Windows?
Is the file C:\windows\system32\shutdown.exe
necessary to shutdown or restart Windows?
Your question of course originates from your answer at https://codegolf.stackexchange.com/a/24011/18907 , in particular from kinokijuf
's comment upon the initial revision of your answer.
As kinokijuf
said, Windows is not Unix. On Unices and Linux, shutdown
is indeed involved in the full shutdown process. It is the program that sends regular warning messages to logged-in users and that writes the /run/nologin
file to prevent further logging-on a short while before the scheduled shutdown time.
On Windows NT, this is not the case.
The "Shut down" action on the "power button" on the Windows Explorer Start menu, the "Shutdown" menu option in Task Manager, REBOOT /S
in TCC or Take Command, and other applications programs that allow you to shut the system down all initiate shutdown by directly calling one of two Win32 API calls: InitiateSystemShutdownEx()
or ExitWindowsEx()
. They don't do things indirectly by running the shutdown
program. (That actually needs more code to do than just calling the Win32 API call.) The shutdown
program, when one is doing a local shutdown, calls those same Win32 API calls too.
It's actually winlogon
, csrss
, and smss
that are the programs that shut down Windows NT. In particular, it is winlogon
that does the main work of processing deferred shutdown requests.
Further reading
- Jonathan de Boyne Pollard (2006). The Windows NT 6 shutdown process. Frequently Given Answers.
-
shutdown
. FreeBSD 9.2 manual pages. 2013-03-19. -
shutdown
.systemd
manual pages. 2013. Freedesktop.org. -
shutdown
.upstart
manual pages. 2009. Canonical Ltd. -
InitiateSystemShutdownEx
. MSDN. Microsoft corporation. -
ExitWindowsEx
. MSDN. Microsoft corporation. -
REBOOT
. Take Command / TCC Help. JP Software.
No.
Explorer doesn't call this command when you shut down from the Start menu.
Shutting down the system is possible with a Win32 API call (@JdeBP's answer provides great details on that if interested). The command is just a convenient way to do it from a script, scheduled task, or the Run dialog.
As explained by ultrasawblade (upvote), the system shutdown is a Win32 API call to: ExitWindowsEx
The link also has an example on how to implement a shutdown from C. Also, you can do it from C# using P/Invoke (Platform Invoke). pinvoke.net has a bunch of signatures available for use:http://www.pinvoke.net/default.aspx/user32/exitwindowsex.html
It is not necessary. shutdown.exe
is just a utility to shut down a local or remote computer. It looks like shutdown.exe
uses the Native API's NtShutdownsystem
. While Windows uses ExitWindowsEx
(as already mentioned).