How to auto-shutdown guest when doing host shutdown?
How to auto-shutdown guest when doing host shutdown?
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
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
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: How to auto-shutdown guest when doing host 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?TonyMo wrote:However, when they do a system shutdown
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
Re: How to auto-shutdown guest when doing host shutdown?
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.noteirak wrote: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?TonyMo wrote:However, when they do a system shutdown
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: How to auto-shutdown guest when doing host shutdown?
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
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!
Manage your VirtualBox infrastructure the free way!
Re: How to auto-shutdown guest when doing host shutdown?
Host: Windows 8 Professional, 32-bitnoteirak 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
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
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" acpipowerbutton
Code: Select all
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" resume
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "XP Home" acpipowerbutton
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.
-
- Posts: 1
- Joined: 17. Apr 2014, 17:07
Re: How to auto-shutdown guest when doing host shutdown?
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:
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.
Thanks.
- Kevin Nelson
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
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "VM NAME" GUI/DefaultCloseAction Shutdown
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.
Thanks.
- Kevin Nelson
Re: How to auto-shutdown guest when doing host shutdown?
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.
Re: How to auto-shutdown guest when doing host shutdown?
The best solution is to use VBoxHeadlessTray which will safely shutdown your headless server when windows host gets shut down.
-
- 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?
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.
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.
-
- Site Moderator
- Posts: 20945
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows, Linux
Re: How to auto-shutdown guest when doing host shutdown?
Darwood, Check this out: 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.
-
- 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?
Nice work, thanks.scottgus1 wrote:Darwood, Check this out: 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.
Re: How to auto-shutdown guest when doing host shutdown?
Thanks, Kevin!