Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait until VirtualBox has finished loading to execute next command in Windows Batch?

I've been having some trouble with a recent CMD batch file I wrote. This is supposed to launch my development environment at work, and for the most part it works:

@echo off
start cmd.exe
start notepad++.exe
start sublime_text.exe
start outlook.exe
start communicator.exe
start "* Starting VirtualBox ..." virtualbox.exe
start sh.exe
start firefox.exe

The challenge I'm facing is that I want to start git-bash, (sh.exe) but in the corporate config virtualbox must be up and running for vagrant, a shell-based virtualbox manager to load properly. So, because of this dependency, I need virtualbox.exe to launch and completely finish loading (we don't need to "start" and boxes) before then launching git-bash shell (sh.exe).

I've searched but fallen short on how to do this. I keep getting results recommending:

  • /wait
  • pinging localhost (n) times to create a timer hack

The problem with these options is the /wait won't move to the next command until VirtualBox is closed -- that's not what I want. The second option is a time-based wait which also does not solve my problem in this case.

What am I doing wrong?

like image 818
Eric Hepperle - CodeSlayer2010 Avatar asked Jun 25 '13 15:06

Eric Hepperle - CodeSlayer2010


2 Answers

Wow! Thanks paulm for inspiration.

Found one great opportunity!

I was browsing build-it guest OS properties with command :

 VBoxControl guestproperty enumerate -patterns *

and I've found a nice property "/VirtualBox/GuestInfo/OS/LoggedInUsers"

During guest OS boot this property changes from "No value set!" through value "0" to "1" (if user logs in automatically). Works fine on both Windows and linux.

>VBoxManage guestproperty get "WIN7_32" "/VirtualBox/GuestInfo/OS/LoggedInUsers"
No value set!

>VBoxManage guestproperty get "WIN7_32" "/VirtualBox/GuestInfo/OS/LoggedInUsers"
Value: 0

>VBoxManage guestproperty get "WIN7_32" "/VirtualBox/GuestInfo/OS/LoggedInUsers"
Value: 1

So you don't need to add anything to Start-up on your guest OS! Sweet!

Also you can even use wait :

VBoxManage guestproperty wait "WIN7_32" "/VirtualBox/GuestInfo/OS/LoggedInUsers"

but keep in mind, that this command will return 0 once guest OS reaches Welcome screen

like image 138
zamuka Avatar answered Oct 14 '22 01:10

zamuka


The "best" way to do this is by using VBoxManage on the host machine combined with VBoxControl on the guest machine using properties.

The way this works is that the host machine will wait for a property to be set, and the guest machine will set this property when ever you consider the machine to have "loaded". For me I simply set the property from a logon script.

So on my Linux host I say:

VBoxManage guestproperty wait My_Virtual_Machine_Name Wait_For_Logon_Event

This will wait/block forever, you can add a timeout if you wish.

Then on the Windows Guest in a logon script or machine start script I execute:

VBoxControl guestproperty set Wait_For_Logon_Event Event_Now_Set

This then causes the execution to continue on the host side:

Name: Wait_For_Logon_Event, value: Event_Now_Set, flags:
like image 22
paulm Avatar answered Oct 14 '22 03:10

paulm