I try to run a VirtualBox Guest OS (Debian) and execute a Script with VB.net
Everything is working fine so far, I can start the VM, log into it, and execute the Script. BUT only if I manually wait long enough, so that the Vbox Guest Service is started in the Guest OS.
I can query the IGuestSession Status via VB.net, but while the OS is booting, I always get the wrong Status (Started)
Here you can see the code to start the VM:
Dim machine As IMachine = virtualBox.FindMachine("Debian")
Dim arr As Array
Dim progress As IProgress = machine.LaunchVMProcess(session, "gui", arr)
progress.WaitForCompletion(60000)
Everything is fine, the VM starts!
No I have a button to start a GuestSession with this code: (for testing purpose)
Dim console As IConsole = session.Console
Dim guest As IGuest = console.Guest()
Dim guestsession As IGuestSession = guest.CreateSession("root", "password", "", "")
Dim guestWaitResults = guestsession.WaitFor(GuestSessionWaitForFlag.GuestSessionWaitForFlag_Start, 0)
MsgBox(guestWaitResults.tostring)
MsgBox(guestsession.Status.ToString)
If I press the button as soon as the VM is started (the VirtualBox Logo is displayed)
I get the following Outputs:
From guestWaitResults: "GuestSessionWaitResult_WaitFlagNotSupported"
From guestsession Status: "GuestSessionStatus_Started"
If I press the Button for testing after about 20 Seconds (as soon as I get the login prompt from the Guest OS), I get the following:
From guestWaitResults: Throws an Error with "waiting for guest process failed: The guest execution service is not ready (yet)
From guestsession Status: "GuestSessionStatus_Error"
If I press the Button for testing after about 60 Seconds (Guest fully started), I get the following Outputs:
From guestWaitResults: "GuestSessionWaitResult_Start"
From guestsession Status: "GuestSessionStatus_Started"
And I am able to execute a process on the Guest.
I don't know why this happenes while booting. As I understand the SDK, I just need to Wait for "guestsession wait for Start". Or I could looping through the "guestsession.status" and wait for it to return "Started".
So it seems to me, that while the Guest is Booting the API Call is returing a wrong value, or am I misunderstanding something? Or am I able to obtain the state of the Guest Service in another way, to execute the script sa soon as the OS is started and the Guest Services are running
I am running VirtualBox 6.1.18 on Windows 10