ITC Judge Bans Xbox in Back Page News

need a script.


3 replies to this topic - - - - -

#1 capr

    Neowinian Senior

  • 2,625 posts
  • Joined: 01-July 05

Posted 08 February 2012 - 12:58

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?


#2 +Phouchg

    Internets Loser

  • 2,355 posts
  • Joined: 28-March 11
  • Location: Past Imperfect
  • OS: WretchedOS 6.1.7601 x64

Posted 08 February 2012 - 17:24

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

Put this in an, e.g., vmsleep.cmd, 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 VBoxManage.

#3 capr

    Neowinian Senior

  • 2,625 posts
  • Joined: 01-July 05

Posted 09 February 2012 - 01:13

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.

#4 AnthonySterling

    Offering bad advice since 23-December 04.

  • 883 posts
  • Joined: 23-December 04
  • Location: North-East, UK

Posted 09 February 2012 - 11:12

View Postcralias, on 08 February 2012 - 17:24, said:

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

Put this in an, e.g., vmsleep.cmd, 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 VBoxManage.

Bravo. (Y)