Today we're going to talk about one of the more esoteric features of Windows. A feature that even some seasoned sysadmins don't know about, and that almost nobody outside of kernel debuggers and device driver writers in Redmond ever use...
Emergency Management Services!
Imagine you have a Windows computer that has suffered a blue screen of death. If you want to sound more savvy, you might call it a STOP error or a bug check. Pictured is a very old example of a BSoD, but it's just so much more iconic than the pretty new Win8 one with the giant frowny face on it.
So you're sitting there staring at a blue screen on the computer's console... can you still reboot the machine gracefully? Or even crazier, could you still run, for example, Powershell scripts on this machine even after it has suffered some massive hardware failure?
Don't reach for that power button just yet, because yes you can!
You might have thought that once a Windows computer has blue-screened, then it's done. It's stopped forever and it cannot execute any more code, period. I thought that myself for a long time. But lo and behold, there's still a little juice left even after you've blue-screened, and all you need is a serial or USB cable. That's where Emergency Management Services comes in.
As the name implies, EMS is typically there for when all else fails. For when your computer has already gone to hell in a handbasket. You could consider it an out-of-band management solution.
Of course you need to have already enabled it beforehand, not after a bug check has already occurred. You'd enable it on Vista/2008 and above like so:
Bcdedit.exe /EMS ON /EMSSETTINGS BIOS
If using a USB port, or
Bcdedit.exe /EMS ON /EMSSETTINGS EMSPORT:COM2 EMSBAUDRATE:9600
If using an RS-232 serial port. (How quaint.)
Now that it's enabled, you can connect to the Special Administration Console (SAC.)
From here, you can launch a command prompt (Cmd.exe,) and from there, you can launch Powershell.exe! All over a serial or USB cable connection. If the regular SAC mode cannot be entered for some reason, then EMS will put you in !SAC mode, where you can still at least read the event logs and reboot the server in a more graceful manner than just pulling the plug.
Mark Russinovich has this to say about the Windows boot up process as it concerns EMS:
"At this point, InitBootProcessor enumerates the boot-start drivers that were loaded by Winload and calls DbgLoadImageSymbols to inform the kernel debugger (if attached) to load symbols for each of these drivers. If the host debugger has configured the break on symbol load option, this will be the earliest point for a kernel debugger to gain control of the system. InitBootProcessor now calls HvlInit System, which attempts to connect to the hypervisor in case Windows might be running inside a Hyper-V host system’s child partition. When the function returns, it calls HeadlessInit to initialize the serial console if the machine was configured for Emergency Management Services (EMS)."
Mark Russinovich, David Solomon, Alex Ionescu, Windows Internals 6th Ed.
So there you have it. Even when faced with a BSoD, if you have an opportunity to shut down or reboot the machine in a more graceful manner than just pulling the electricity from it, then you should do it.