[Solved] Closing windows guest on application close ?

Discussions about using Windows guests in VirtualBox.
Post Reply
oukourj
Posts: 6
Joined: 3. Jul 2019, 11:40

[Solved] Closing windows guest on application close ?

Post by oukourj »

Hi,

We use a WinXP guest to run very old programs.
I want to integrate this seamlessly, and I'd like the VM to completely shut-down when the application run in the guest is shut down.

AKA, how would you trigger a VM shutdown from within the guest when an application within the guest is closed ?

Thanks for any ideas!
Last edited by socratis on 5. Jul 2019, 10:24, edited 1 time in total.
Reason: Marked as [Solved].
andyp73
Volunteer
Posts: 1631
Joined: 25. May 2010, 23:48
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Assorted Linux, Windows Server 2012, DOS, Windows 10, BIOS/UEFI emulation

Re: Closing windows guest on application close ?

Post by andyp73 »

oukourj wrote:AKA, how would you trigger a VM shutdown from within the guest when an application within the guest is closed ?
The same way that you would shutdown a physical PC running Windows when a specific application gets closed. Google is probably your friend here.

My first guess would be that you could use a batch file to start the application using "start /wait ..." and then when it continues execution call Windows XP's shutdown.exe application.

-Andy.
My crystal ball is currently broken. If you want assistance you are going to have to give me all of the necessary information.
Please don't ask me to do your homework for you, I have more than enough of my own things to do.
oukourj
Posts: 6
Joined: 3. Jul 2019, 11:40

Re: Closing windows guest on application close ?

Post by oukourj »

Ah, indeed, that's an idea that could definitely work but I omitted specifying that I'd like to do a hard shut-down, like if I closed the VM window and selected to just turn off the computer instead of shutting down Windows the normal way.
I'd like it to feel like an application, so that users don't see the LogOff/Shutdown window popping before it actually closes the VM.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Closing windows guest on application close ?

Post by scottgus1 »

oukourj wrote:I'd like to do a hard shut-down, like if I closed the VM window and selected to just turn off the computer instead of shutting down Windows the normal way.
Closing the guest window without a proper shutdown of the guest OS is like pulling the power cord on a real PC. Doing this is very bad for a computer, whether virtual or physical. I would recommend a different thought, or you'll find your guest going south on you soon.

The guest window runs in the context of the host OS. You would have to issue command on the host PC in response to certain of all the random commands happening on the guest PC. Virtualbox does not come with a system to listen all commands & mouse clicks in the guest then issue host command in response.*

Take Virtualbox out of the equation for a moment and consider that what you're really trying to do is have the closing of an application on one computer do things on another computer. Try to figure out how you'd do that with two computers side-by-side, then apply the solution to your host & guest.

* There is a way through Guest Additions to issue messages in text between host and guest, see section 8.30 in the Virtualbox manual:
Vboxmanage.exe setextradata <vmname> <keyname> <textvalue>
Vboxmanage.exe getextradata <vmname> <keyname>
In the guest the same commands can be used, except use VboxControl.exe instead of Vboxmanage.exe. You could start your guest application with a batch file as Andy recommended, then when the application is closed, issue a setextradata to set a particular 'flag' key in the guest. A host batch file would be neeeded to use getextradata in a time-delayed loop to watch for the change of the guest's 'flag', change it back, then issue the desired command on the host.

Another alternative is to leave your guest on all the time, using the VboxVMservice add-on. Set the guest to save-state in VboxVMservice. Your guest will run headless (meaning the guest window is running invisible) and activate the Virtualbox Remote Desktop server in the guest settings. When you want to use the guest application, run the host's Remote Desktop client to access the guest window. The benefit of running the guest as a service is that it will be OK through a host shut-down/reboot.

One might think that starting the guest with a detached GUI might be a way. However, while Vboxmanage commands can be used to show the guest window, there is no Vboxmanage command to hide the guest window. Only the Virtualbox window commands in the main window or the guest's Virtualbox menu bar, or a custom host key command can hide the guest window while leaving the guest running.
oukourj
Posts: 6
Joined: 3. Jul 2019, 11:40

Re: [Solved] Closing windows guest on application close ?

Post by oukourj »

HI !
Thanks for your answer.

Actually it made me stumble on my final solution :

VBoxManage run, with it's wait-for-stdout option.
I launch the app with a batch, and this batch waits until the application is closed thanks to aformentioned command.
Then, the next line of the batch instructs to poweroff the VM.

Don't worry, I reaload the same initial state each time.

Making Solved. (actually I don't know how so this title just changed to Solved :))
Post Reply