Batch file as shortcut to guest program on host?

Discussions related to using VirtualBox on Windows hosts.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

Making those changes seems to have changed nothing.

How do I view what's in guestproperty at a given moment? I have a feeling it isn't "echo %guestproperty%".
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

Lendri Mujina wrote:How do I view what's in guestproperty at a given moment?
You could run a 'vboxmanage guestproperty get' from the command prompt. It will display the value in the command prompt window.

Please post your batch files again, let's see what you've got after the changes.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

scottgus1 wrote:
Lendri Mujina wrote:How do I view what's in guestproperty at a given moment?
You could run a 'vboxmanage guestproperty get' from the command prompt. It will display the value in the command prompt window.

Please post your batch files again, let's see what you've got after the changes.
I continue to get absolutely nothing.

Sorry about the delay, it's just been one hell of a week.

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
:DoUntil
PING -n 5 127.0.0.1 > nul
vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > "C:\Users\tcbro\Dropbox\tempfile.txt"
find /i /n "Value: 0" tempfile.txt > nul
if %Errorlevel%==0 goto EndLoope
ECHO No response from guest. Retrying...
GOTO DoUntil
:EndLoope
ECHO Response from guest recieved. Starting program.
VBoxManage --nologo guestcontrol "Windows XP" run --exe "C:\SIERRA\PA4GOLD\PRTARTST.EXE" --wait-stdout --username User --password admin

Code: Select all

CD "C:\Program Files\Oracle\"
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
ECHO If it hasn't opened by now, just shut down.
PAUSE
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

Things are coming along. Here's the glitches I see:

In the host script:
Lendri Mujina wrote:vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > "C:\Users\tcbro\Dropbox\tempfile.txt"
find /i /n "Value: 0" tempfile.txt > nul
Commands in a batch file that are told to look for a file, like the find command, will start looking in the folder the batch file exists first, then in all the paths stored in the system's PATH variable. So 'find' is looking for 'tempfile.txt' in the batch file's folder. However, the redirected 'guestproprty get' file is being put in "C:\Users\tcbro\Dropbox\", so it cannot be found by 'find'. If you're not certain that the folder the batch file is in would be a good place to have the text file, the Temp folder would be a possible place. Try making these lines:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul


In the VM script:
Lendri Mujina wrote:CD "C:\Program Files\Oracle\"
In the VM this would be:

CD "C:\Program Files\Oracle\VirtualBox Guest Additions"
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

Still no good. Thanks for being patient, though, at any rate.
Is this something you've ever done successfully for your own machines before?

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
:DoUntil
PING -n 5 127.0.0.1 > nul
vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul
if %Errorlevel%==0 goto EndLoope
ECHO No response from guest. Retrying...
GOTO DoUntil
:EndLoope
ECHO Response from guest recieved. Starting program.
VBoxManage --nologo guestcontrol "Windows XP" run --exe "C:\SIERRA\PA4GOLD\PRTARTST.EXE" --wait-stdout --username User --password admin

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox Guest Additions"
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
PING -n 2 127.0.0.1 > nul
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
ECHO If it hasn't opened by now, just shut down.
PAUSE
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

I have used this process before, as a VM OS heartbeat indicator. Will look into it later today.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

I used your scripts on my Win10 host and XP VM and got a successful run:
XP guestproperty source works.png
XP guestproperty source works.png (45.42 KiB) Viewed 3802 times
XP VM script running 2.png
XP VM script running 2.png (29.62 KiB) Viewed 3802 times
I did notice that when the XP VM started, the host script stayed in the loop and the VM script did not run until I had logged in on the VM. Then the VM script ran and the host script dropped out of the loop to run the next commands. Auto-Login on the VM would be necessary to run the batch file. Have you set your VM to auto-login?
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

I have. That was one of the first things I did after installing the VM.

I'll see if there's something I missed in your execution of it tomorrow.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

As a suggestion, manually enter each command (not the loop commands) in a command prompt, to see if an error occurs.

For example, run each of these in the host command prompt:

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey


The last 'guestproperty get' should print 'Value: 1' in the command prompt.

Then in the VM's command prompt, enter this command:

CD "C:\Program Files\Oracle\VirtualBox Guest Additions"
VBOXCONTROL guestproperty set /vmcontrol/readykey 0


then repeat this in the host command prompt:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey

It should print 'Value: 0' in the command prompt.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

I'm sorry for the delay. But yes, entering each command manually worked.
And so did making a batch with those exact same commands.

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
VBOXMANAGE guestproperty get "Windows XP" /vmcontrol/readykey
ECHO Wait until the guest command window finishes to check value.
PAUSE
VBOXMANAGE guestproperty get "Windows XP" /vmcontrol/readykey
PAUSE

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox Guest Additions"
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
So the problem must be something to do with either the loop or the "find" command.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

I've found ONE problem (the ping delay was causing issues), and now it successfully detects the value, but the program still doesn't start.

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
VBOXMANAGE guestproperty get "Windows XP" /vmcontrol/readykey
ECHO Wait until the guest command window finishes.
PAUSE
VBOXMANAGE guestproperty get "Windows XP" /vmcontrol/readykey
:DoUntil
find /i /n "Value: 0" %temp%\tempfile.txt > nul
if %Errorlevel%==0 goto EndLoope
ECHO No response from guest.
VBOXMANAGE guestproperty get "Windows XP" /vmcontrol/readykey
PAUSE
GOTO DoUntil
:EndLoope
ECHO Response from guest recieved. Starting program.
VBOXMANAGE guestcontrol run --exe "C:\WINDOWS\system32\sol.exe"

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox Guest Additions"
VBOXCONTROL guestproperty set /vmcontrol/readykey 0
I've also tried it with the VM name and the --nologo thing, but the exact same response... or lack thereof.

This is what happened when I tried to run the program-starting command manually after the VM was already active:
C:\Program Files\Oracle\VirtualBox>VBoxManage --nologo guestcontrol "Windows XP" run --exe "C:\SIERRA\PA4GOLD\PRTARTST.EXE" --wait-stdout --username User --password admin
VBoxManage.exe: error: Waiting for guest process failed: The specified user was not able to logon on guest
VBoxManage.exe: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestSessionWrap, interface IGuestSession, callee IUnknown
VBoxManage.exe: error: Context: "WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), 30 * 1000, &enmWaitResult)" at line 893 of file VBoxManageGuestCtrl.cpp
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

This sure is a hard nut to crack, isn't it? :shock:

On my host the ping delay worked. With no form of delay, the loop in the host batch file will full-throttle the processor core on which it runs and may become unresponsive. There are other ways to delay if ping is failing in your loop, see https://www.robvanderwoude.com/wait.php

I believe that the error means that the VM was in a state where that program couldn't start. Was the VM fully logged into the account whose username and password your command was using when the guest control command was attempted?

I'd also try to run standard Windows programs like mspaint.exe or calc.exe in your script tests, then try your other programs when the Windows programs start up reliably.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

scottgus1 wrote:This sure is a hard nut to crack, isn't it? :shock:

On my host the ping delay worked. With no form of delay, the loop in the host batch file will full-throttle the processor core on which it runs and may become unresponsive. There are other ways to delay if ping is failing in your loop, see https://www.robvanderwoude.com/wait.php

I believe that the error means that the VM was in a state where that program couldn't start. Was the VM fully logged into the account whose username and password your command was using when the guest control command was attempted?

I'd also try to run standard Windows programs like mspaint.exe or calc.exe in your script tests, then try your other programs when the Windows programs start up reliably.
It was not only fully-logged in, but already running. I was able to start the programs through the Start Menu.

And this fails even with the Windows programs (I tried the calculator and Solitaire).
I just don't know what could be interfering. Maybe I have the wrong syntax? Maybe vboxmanage is corrupted? I just have no idea. This should really be a much more simple matter than it's turning out to be...
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Batch file as shortcut to guest program on host?

Post by scottgus1 »

This is really puzzling, especially since I was able to use your script here viewtopic.php?f=6&t=103236&start=15#p502294 on my host and XP VM and it worked perfectly:

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
:DoUntil
PING -n 5 127.0.0.1 > nul
vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul
if %Errorlevel%==0 goto EndLoope
ECHO No response from guest. Retrying...
GOTO DoUntil
:EndLoope
ECHO Response from guest recieved. Starting program.
VBoxManage --nologo guestcontrol "Windows XP" run --exe "mspaint.exe" --wait-stdout --username {VMaccountname} --password {VMaccountpassword}
pause
I discovered it is possible to pipe | the 'guestproperty get' into 'find' on one line without going to a text file. We can replace:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul


with:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey|find /i /n "Value: 0"

However, the code above in CODE tags worked fine for me. The VM started, the host batch waited until the VM was running and logged in and the VM batch file ran, then the Paint program started, the host batch file waited for me to close Paint, then the batch file finished.

I am not certain what else to do on your end. Maybe state where each batch file is placed in your host and VM and how they are launched? The host's batch file is started from my desktop, and my VM's batch file is started via a shortcut in the VM's auto-log-on'ed account's Start menu Startup folder.
Lendri Mujina
Posts: 17
Joined: 29. Jun 2021, 00:33

Re: Batch file as shortcut to guest program on host?

Post by Lendri Mujina »

scottgus1 wrote:This is really puzzling, especially since I was able to use your script here viewtopic.php?f=6&t=103236&start=15#p502294 on my host and XP VM and it worked perfectly:

Code: Select all

CD "C:\Program Files\Oracle\VirtualBox"
VBOXMANAGE --nologo startvm "Windows XP"
VBOXMANAGE guestproperty set "Windows XP" /vmcontrol/readykey 1
:DoUntil
PING -n 5 127.0.0.1 > nul
vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul
if %Errorlevel%==0 goto EndLoope
ECHO No response from guest. Retrying...
GOTO DoUntil
:EndLoope
ECHO Response from guest recieved. Starting program.
VBoxManage --nologo guestcontrol "Windows XP" run --exe "mspaint.exe" --wait-stdout --username {VMaccountname} --password {VMaccountpassword}
pause
I discovered it is possible to pipe | the 'guestproperty get' into 'find' on one line without going to a text file. We can replace:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey > %temp%\tempfile.txt
find /i /n "Value: 0" %temp%\tempfile.txt > nul


with:

vboxmanage guestproperty get "Windows XP" /vmcontrol/readykey|find /i /n "Value: 0"

However, the code above in CODE tags worked fine for me. The VM started, the host batch waited until the VM was running and logged in and the VM batch file ran, then the Paint program started, the host batch file waited for me to close Paint, then the batch file finished.

I am not certain what else to do on your end. Maybe state where each batch file is placed in your host and VM and how they are launched? The host's batch file is started from my desktop, and my VM's batch file is started via a shortcut in the VM's auto-log-on'ed account's Start menu Startup folder.
That is literally the exact same place where I'm putting it on both accounts. Host's batch file is on the desktop, guest's in Startup folder.
Like I said, the batch file works. But the program startup doesn't. Even when the command is put in manually without the batch file. Is there some kind of VM setting that might be interfering with that?
Post Reply