Sign in to follow this  

need a script.

Recommended Posts

capr    36

Hey, I would like a script that will pause all my virtualbox guests and then puts the host to sleep.

Is this possible? Where should I start?

Share this post


Link to post
Share on other sites
Phouchg    2,050

VirtualBox and its VMs can be controlled with its own command line tool VBoxManage. This tool sits in the installation directory.

For your exact task - pausing all running VMs (even though you actually don't need to explicitly pause them as putting computer to sleep will perfectly save their state anyway) - it would be like this:


@echo off
cd /d %VBOX_INSTALL_PATH%
for /f "delims={" %%f in ('vboxmanage list runningvms') do vboxmanage controlvm %%f pause
powercfg -h off
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby
powercfg -h on
for /f "delims={" %%f in ('vboxmanage list runningvms') do vboxmanage controlvm %%f resume
[/CODE]

Put this in an, e.g., [font=courier new,courier,monospace]vmsleep.cmd,[/font] then execute it as needed.

Note that here putting a computer to sleep via command line is a cheap hack. It disables Hibernation first and then re-enables it after wake up, effectively reenabling it even if disabled by someone else. It is possible to invoke Sleep straightforward with Powershell, if that presents a problem.

And see VirtualBox's own bundled help file (or online: https://www.virtualb...anual/ch08.html) for more commands of [font=courier new,courier,monospace]VBoxManage[/font].

  • Like 1

Share this post


Link to post
Share on other sites
capr    36

Oh wow it does work.... I can just put the host to sleep and everything works fine when I wake it!!

thank you for the script. I will keep it in mind for when I need to shut down the host but dont' want to shut down and restart all the VMs individually.

Share this post


Link to post
Share on other sites
AnthonySterling    11

VirtualBox and its VMs can be controlled with its own command line tool VBoxManage. This tool sits in the installation directory.

For your exact task - pausing all running VMs (even though you actually don't need to explicitly pause them as putting computer to sleep will perfectly save their state anyway) - it would be like this:


@echo off
cd /d %VBOX_INSTALL_PATH%
for /f "delims={" %%f in ('vboxmanage list runningvms') do vboxmanage controlvm %%f pause
powercfg -h off
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby
powercfg -h on
for /f "delims={" %%f in ('vboxmanage list runningvms') do vboxmanage controlvm %%f resume
[/CODE]

Put this in an, e.g., [font=courier new,courier,monospace]vmsleep.cmd,[/font] then execute it as needed.

Note that here putting a computer to sleep via command line is a cheap hack. It disables Hibernation first and then re-enables it after wake up, effectively reenabling it even if disabled by someone else. It is possible to invoke Sleep straightforward with Powershell, if that presents a problem.

And see VirtualBox's own bundled help file (or online: https://www.virtualb...anual/ch08.html) for more commands of [font=courier new,courier,monospace]VBoxManage[/font].

Bravo. (Y)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.