• 0

need a script.


Question

3 answers to this question

Recommended Posts

  • 0

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].

Link to comment
https://www.neowin.net/forum/topic/1056788-need-a-script/#findComment-594640692
Share on other sites

  • 0

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)

Link to comment
https://www.neowin.net/forum/topic/1056788-need-a-script/#findComment-594642318
Share on other sites

This topic is now closed to further replies.