Unattended ACPI Shutdown of Windows VMs

As part of a backup script I have some VirtualBox machines shutdown gracefully using the VBoxManage command:

VBoxManage controlvm "$VM_NAME" acpipowerbutton

This command emulates pressing (not holding) the power button on a modern computer. A compliant operating system should see the event and trigger a shutdown or other response.

For ACPI shutdown events to work properly with Windows VMs that share resources to remote users, changes must be made to allow shutting down when a user is not logged in locally to the computer. Two methods can be used to enable the feature, both of which are discussed below. You may need to reboot your guest OS after making the changes before they will work.

Method 1: Group Policy Editor

Open the Run dialog (Windows key + r), type in “gpedit.msc” and click “OK” to open the Group Policy Editor.

Once in the Group Policy Editor expand “Computer Configuration“, then “Windows Settings“, then “Security Settings“, then “Local Policies” and click on “Security Options” as shown below

Scroll down the list in the right pane and find “Shutdown: Allow system to be shut down without having to log on“. In server versions of Windows this option will be “Disabled” by default.

Double click on “Shutdown: Allow system to be shut down without having to log on” and select “Enabled“. Click Apply and OK to save the changes.

That’s it, this feature is now enabled.

Method 2: Registry Editor

Open the Run dialog (Windows key + r), type in “regedit” and click “OK” to open the Registry Editor.

In the left window pane expand “My Computer” to find “HKEY_LOCAL_MACHINE“, then “SOFTWARE“, then “Microsoft” then “Windows“, then “CurrentVersion“, then “policies“, then “system” as shown below

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system

In the right pane double click on “shutdownwithoutlogon” and change the value to “1“. Since the value is less than 10 is doesn’t matter if Hexadecimal or Decimal is selected. Click “OK” to save.

The value next to “shutdownwithoutlogon” should now show the value of “0x00000001 (1)” as shown below.

Power button in Power Options

Make sure that the power button is configured correctly in “Power Options“. Open the Control Panel and double click on the “Power Options” icon.

Click on the “Advanced” tab. In the “Power buttons” section the value under “When I press the power button on my computer:” should be set to “Shut down” as shown below.

Disable Shutdown Warning

Windows warns you when you are about to shutdown and take away resources from that appear to be in use. On a server there is a pretty good chance that resources will be in use when it comes time to shutdown. The confirmation dialog box is not conducive to scripting because manual intervention is required.

Although this warning message can’t be removed completely it can be configured to wait only momentarily before automatically selecting the affirmative option and proceeding with the shutdown. To set a timeout, open the Registry Editor (as described earlier) and navigate to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows

Right click in the free space in the right-hand window pane and choose “New” then choose “DWORD Value

Replace “New Value #1” with ShutdownWarningDialogTimeout. It should look like below if you’ve done it correctly.

Now double click on “ShutdownWarningDialogTimeout” to change it’s value. This value is the amount of time to display the warning message before continuing with the shutdown. I’ve set the value to “1“, but it might be wise to set it high enough so that if an actual person was orchestrating the shutdown the notice could serve it’s purpose and alert the operator that they might want to re-think their plan.

If everything worked it should look similar to the image below

For your convenience

Although these steps are pretty quick to implement, they can be annoying to implement on each of your virtualized servers. For your convenience I’ve included a a registry file which can be merged into your existing hive to implement the settings to allow both shutdown while logged off and automatic dismissal of the shutdown warning notice of connected users.

ACPI_Friendly_Shutdown.reg

To add the settings to the registry double click the registry file. Windows will prompt you to confirm you wish to merge the changes.

If everything imported OK, Windows will let you know

If that doesn’t work…

There may be cases where the above changes are not enough. It is possible to configure Windows to select the default answer from a MessageBox dialog without displaying it. You should use this option as a last result as it may will have unintended consiquences. For more information see the Microsoft article at:
http://msdn.microsoft.com/en-us/library/ms940850%28v=winembedded.5%29.aspx

To enable this feature, open the registry editor (as described previously) and navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrenctControlSet\Control

Right-click on “Control” and choose “New” followed by “Key

The words “New Key #1” will be highlighted, begin typing to overwrite the default value with “Error Message Instrument

In the empty space on the right-side pane, right-click and choose “New“, followed by “DWORD Value

Set the name to “EnableDefaultReply”

Double-click on “EnableDefaultReply” to set the value. Type the value “1” into the “Value data” field and click “OK


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.