How to auto-shutdown guest when doing host shutdown?

Discussions related to using VirtualBox on Windows hosts.

How to auto-shutdown guest when doing host shutdown?

Postby TonyMo » 18. Jan 2013, 15:13

I have a Linux guest running on a Windows 7 Pro host. I have the guest started automatically at system startup using a script that does a VBoxManage startvm. This starts up the guest giving the user a guest window on their desktop (they don't actually need to use the guest window, although it is useful for when a developer has to debug things).

I have installed acpid on the Linux guest, and an ACPI Shutdown works correctly when invoked manually.

I need the user to be able to do a normal Windows Shutdown on the host without having to manually close the guest VM themselves. However, when they do a system shutdown, the Windows Close action on the VM window brings up the menu "Power Off", "Shutdown" or "Save State" and requires a manual answer. This prevents the host system shutdown until answered.

How can I set it so that the VM gets given an ACPI Shutdown automatically when Windows wants to close the guest window?

Things I have tried:

1. VBoxManage setextradata "VM name" GUI/RestrictedCloseActions SaveState,PowerOff,Restore
This makes the window-closing dialog box ONLY contain the Shutdown option, but STILL DOESN'T DO IT AUTOMATICALLY! It waits for the user to click OK.

2. Creating a StopVM.bat script containing VBoxManage controlvm "VM name" acpipowerbutton, and used gpedit.msc to set this as a Logoff script for the user.
This doesn't help, because Windows insists on closing all its windows before executing the logoff scripts. So it still gets stuck at 1 above, waiting for the user to click OK.

What VirtualBox really, REALLY needs is an option settable in the manager for each VM for "GUI Close Action", offering Save State, PowerOff, Shutdown, Restore or Ask.

Can anyone suggest a way to make it do what I need? I'm using 4.2.6.

Cheers
Tony
TonyMo
 
Posts: 3
Joined: 21. Sep 2012, 14:07

Re: How to auto-shutdown guest when doing host shutdown?

Postby noteirak » 18. Jan 2013, 15:53

TonyMo wrote:However, when they do a system shutdown

Could you give a bit more information on that : how do they do it exactly? Via the power button of the host, via the shut down power option of the start menu? via a script/custom gui item?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5224
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: How to auto-shutdown guest when doing host shutdown?

Postby TonyMo » 18. Jan 2013, 16:18

noteirak wrote:
TonyMo wrote:However, when they do a system shutdown

Could you give a bit more information on that : how do they do it exactly? Via the power button of the host, via the shut down power option of the start menu? via a script/custom gui item?


Yes, just from the Start Menu, although it would apply to any other way of invoking shutdown (e.g. set in Windows Control Panel Power Options). The non-technical users of this system (which is laptop-based) will know about shutting down from the start button, but I'm trying to avoid them having to remember to shut down the VM first.
TonyMo
 
Posts: 3
Joined: 21. Sep 2012, 14:07

Re: How to auto-shutdown guest when doing host shutdown?

Postby noteirak » 18. Jan 2013, 19:00

Could you try with creating a task in the task scheduler, put trigger as user loggoff and run program as action, with the vboxmanage command line?
I cannot try on my system for now, but it's worth a shot to see if it is started BEFORE the logoff procedure or after, like via gpo
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5224
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: How to auto-shutdown guest when doing host shutdown?

Postby Gord » 7. Feb 2013, 19:50

noteirak wrote:Could you try with creating a task in the task scheduler, put trigger as user loggoff and run program as action, with the vboxmanage command line?
I cannot try on my system for now, but it's worth a shot to see if it is started BEFORE the logoff procedure or after, like via gpo

Host: Windows 8 Professional, 32-bit
Guest: Windows XP Home, 32-bit
VirtualBox version: 4.2.6r82870

I'm looking for the same solution as Tony, so I thought I'd try the Task approach. In Windows' Task Scheduler there is an option to trigger a task "At log on" but I couldn't find an option for "At log off", so I looked through the Event Logs and found the event

Log: System
Source: User32
Event ID: 1074
Description: The process C:\Windows\Explorer.EXE (WIN8INSPIRON) has initiated the restart of computer...

Unfortunately, that event appears to happen after Windows sends the "close" message to the VM's window, so the VM goes into a Paused state and prompts for the desired action (save state, shut down, or power off). Windows detects that the VM window is still open and shows the "these programs are preventing your computer from restarting" message. After a minute or two the reboot is cancelled and I'm taken back to the desktop where the VM is patiently waiting for my selection.

I even tried changing the batch file from...

Code: Select all   Expand viewCollapse view
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" acpipowerbutton

...to...

Code: Select all   Expand viewCollapse view
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" resume
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" acpipowerbutton

...to see if I could "un-pause" the VM but it didn't help. :(

So, in Tony's case perhaps the best solution would be to use VBoxVmService since the users don't really need a guest window. The downside is that using VBoxVmService precludes using the VirtualBox Manager GUI, so to "get your hands on" the guest you'd have to either

- "remote desktop" into it, or
- stop it via the service and then start it again via the GUI.
Gord
 
Posts: 6
Joined: 7. Feb 2013, 16:58

Re: How to auto-shutdown guest when doing host shutdown?

Postby KevinNelson » 17. Apr 2014, 17:38

I know this post is over a year old, but I had this same issue and desperately wanted to solve it. I want to post because I found an undocumented way to solve this problem, and it may be helpful to other people that are having this issue.

I found the solution to this issue by looking at the source code. I was thinking about modifying the source code to solve the issue, but I found that someone already had. It just wasn't documented. The code change occurred in April 2013 (after the original post) so it was not solvable back then...

Finally the solution:
Code: Select all   Expand viewCollapse view
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "VM NAME" GUI/DefaultCloseAction Shutdown

NOTE: Make sure you shutdown and restart your VM after you type that command as it doesn't take effect immediately.

You can replace Shutdown with: SaveState, PowerOff, or PowerOffRestoringSnapshot. I have not tested those, but I got the names from the source code.

Now when I shutdown/reboot Windows my VMs will automatically get gracefully shutdown as well. :D

Thanks.

- Kevin Nelson
KevinNelson
 
Posts: 1
Joined: 17. Apr 2014, 17:07

Re: How to auto-shutdown guest when doing host shutdown?

Postby rewen » 25. Jun 2014, 20:45

I'm searching for the same type of solution, however my VMs run headlessly and so the suggestion from the previous post doesnt' work for me. :(
rewen
 
Posts: 1
Joined: 25. Jun 2014, 20:44

Re: How to auto-shutdown guest when doing host shutdown?

Postby moloth » 10. Aug 2014, 09:41

The best solution is to use VBoxHeadlessTray which will safely shutdown your headless server when windows host gets shut down.
moloth
 
Posts: 3
Joined: 30. Jan 2009, 10:00

Re: How to auto-shutdown guest when doing host shutdown?

Postby Darwood » 20. Nov 2014, 11:34

Hi Kevin

Is there a way of doing this for VMs that I start via the GUI? At the moment when Windows Updates decide to restart my machine the VMs are shown as Aborted when I reload VirtualBox.
Darwood
 
Posts: 7
Joined: 27. Apr 2011, 16:53
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Windows XP and Windows 7

Re: How to auto-shutdown guest when doing host shutdown?

Postby scottgus1 » 20. Nov 2014, 20:19

Darwood, Check this out: https://forums.virtualbox.org/viewtopic.php?f=6&t=64741 (I posted this in the suggestions forum too, on the Windows Update reboot issue) Windows Updates get run from a VBS script, instead of from the desktop, and the batch file calling the script can shut down or save state running guests beforehand.
scottgus1
Site Moderator
 
Posts: 18116
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to auto-shutdown guest when doing host shutdown?

Postby Darwood » 21. Nov 2014, 12:32

scottgus1 wrote:Darwood, Check this out: https://forums.virtualbox.org/viewtopic.php?f=6&t=64741 (I posted this in the suggestions forum too, on the Windows Update reboot issue) Windows Updates get run from a VBS script, instead of from the desktop, and the batch file calling the script can shut down or save state running guests beforehand.

Nice work, thanks.
Darwood
 
Posts: 7
Joined: 27. Apr 2011, 16:53
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Windows XP and Windows 7

Re: How to auto-shutdown guest when doing host shutdown?

Postby ClemH » 28. Jan 2015, 20:30

Thanks, Kevin!
ClemH
 
Posts: 2
Joined: 28. Jan 2015, 20:28


Return to VirtualBox on Windows Hosts

Who is online

Users browsing this forum: No registered users and 37 guests