Launch an application in Windows from the Ubuntu desktop

18,596

Solution 1

There are some limitation from the Windows guests but to run a guest application in seamless mode from a script that can be put in a launcher we tested the following procedure:

  • Start VirtualBox Manager
  • Log in to windows with you user and password
  • Switch to seamless mode Host + L
  • In seamless mode save the machine's state

Now we can get full command line control over the virtual machine with the following commands:

  • Start the virtual machine from seamless save state

    VBoxManage startvm "<Name_of_VM>"
    

    or (for the Qt frontend)

    VirtualBox --startvm "<Name_of_VM>"
    
  • Run an application in the VM

    VBoxManage --nologo guestcontrol "<Name_of_VM>" run --exe "C:\\full\\path\\to\\program.exe" --username windowsuser --password password --wait-stdout
    
  • Terminate VM in save state

    VBoxManage controlvm "Name_of_VM" savestate
    

Put these in a script to enjoy seamless Windows application windows on your Ubuntu desktop.

In case you have set up a passwordless Windows logon this will not work. See in the Virtual Box Manual for limitations and how to configure Windows to get it working.

Also, to use accounts without or with an empty password, the guest's group policy must be changed. To do so, open the group policy editor on the command line by typing gpedit.msc, open the key Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options and change the value of Accounts: Limit local account use of blank passwords to console logon only to Disabled.

On operating systems without the Group Policy Editor (gpedit.msc), such as Home editions of Windows, creating a DWORD at the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\limitblankpassworduse and setting it to zero will achieve the same effect, according to this answer.

Solution 2

This is more a hint than an answer, but it's too big for a comment.

You should probably look at this. According to the docs, this command, run from the host OS (I' assuming an Ubuntu host and Windows guest):

VBoxManage guestcontrol "Windows XP Pro" execute --image "cmd.exe" --username javier --verbose "/c" "regedit.exe"

Should open regedit in Windows (the guest), but I have never been able to make it work.

You can also use

VBoxManage showvminfo "Windows XP Pro" | grep State

to check if a VM is running or not.

Solution 3

I deleted the original idea when I realized that it won't work because Linux won't be able to access the windows partition in a VM if it's not running already. There may be a more complex way to do it, but I don't know if it's really worth it.

It may be feasible to have a common shared directory, and a script in Windows would always check this directory to see if it is empty or not. If not, it would run the scripts in the directory, which would be put there by the Ubuntu system before running the VM.

You could have a 2nd script that deletes the 1st one so it doesn't run the next time.

Solution 4

I wanted the same thing and ended up solving it without using guestcontrol. On my MacOS X host I have a folder (named Windows) that my vbox client running a Win7 has mapped as Z:. I use dummy-files to communicate between host and my clients like this:

On the Mac host: - created one shell-script complete with an icon for each windows application I wanted to start in the Win-client. What they basically do is makes sure that the VirtualBox hasn't been started before and then creates a "start this particular application"-file in the shared folder that Windows can read after startup. Example of what such a script looks like is this:

#!/bin/bash

# bail if vbox is already started/running windoze...
ps ax | grep -v grep | grep 'Windows 7' > /dev/null
if [ $? -eq 0 ]; then
  echo "Sorry, Windows is already running."
  exit 0
fi

# send a message to Windoze which program to start...
touch /Users/urban/Documents/Windows/START_TS2000I.TXT

# startup Windoze in seamless mode
vboxmanage setextradata 'Windows 7' GUI/Seamless on
vboxmanage startvm 'Windows 7' &

exit 0

Then on the windows client I have a matching script (BAT-file) in the Startup-folder that looks like this:

@echo off
pushd "C:\Program Files\Omega Research\Program"
if exist Z:\start_ts2000i.txt start ORTrade.exe
if exist Z:\start_ts2000i.txt del Z:\start_ts2000i.txt
.
.
.
exit 0

This way, any time I want to add a new client-startup icon on my Mac I copy the shell script, invent a new dummy file and add the matching startup lines in the BAT-script on the client. Works great and I think it is in line with Martys idea in the previous post.

Share:
18,596

Related videos on Youtube

Anderson Green
Author by

Anderson Green

I write source-to-source compilers in JavaScript using Peggyjs. I also write compilers in Prolog. For reference, I also have a list of source-to-source compilers on GitHub.

Updated on September 18, 2022

Comments

  • Anderson Green
    Anderson Green over 1 year

    I'd like a write a shell script in Ubuntu that does the following:

    1. Boot up a Windows 7 guest OS in Virtualbox, if it isn't running already.

    2. Run a shell script in Windows, where the shell script is invoked from the Ubuntu host operating system.

    My goal is to create an application launcher on the Ubuntu host desktop for an application on the guest OS. For example, I could create a shortcut for Visual Studio on the Ubuntu desktop that launches Visual Studio in Windows. I've always wanted to be able to launch Windows applications directly from the Ubuntu desktop instead of waiting for Windows to start up before clicking an application shortcut.

  • Anderson Green
    Anderson Green almost 12 years
    I'd like to create a shortcut for Visual Studio and a shortcut for Internet Explorer that can be invoked from the Ubuntu desktop(so that they run in the virtual machine). Can this be done using the method you described?
  • Anderson Green
    Anderson Green almost 12 years
    I'd like to know whether the inverse could also be done - launching a host application (such as Kolourpaint) from the guest operating system.
  • Anderson Green
    Anderson Green almost 12 years
    Could the inverse be done using guest additions, then?
  • Anderson Green
    Anderson Green almost 12 years
    Also, are you referring to the Windows startup folder or the Ubuntu startup applications list?
  • Deepak Verma
    Deepak Verma almost 12 years
    Sorry, I realized my first idea was flawed, because the windows folder doesn't exist until the VM is running. I revised my answer completely, and I hope it's not too confusing.
  • Anderson Green
    Anderson Green almost 12 years
    Parallels has a feature called "shared applications" that seems very close to what I was looking for: download.parallels.com/desktop/v6/docs/en/…
  • Deepak Verma
    Deepak Verma almost 12 years
    Well, if you think you want to pursue my idea, and need any details, I'll try to help you out. It's not too hard, I don't think, just requires a bit of understanding of several steps involved.
  • Deepak Verma
    Deepak Verma almost 12 years
    Interesting ideas, and I think it could be used as another way to accomplish the task. The guest could be launched from the host, then when it's running, the command could probably be made to work to run a command. For a programmer, it may be an easier way than my idea; it involves using "sleep" in a loop to wait for the VM to be up, but it can all be done from the host, with a single script.
  • Deepak Verma
    Deepak Verma almost 12 years
    I just tried out your first execute command and was able to run Quicken on my first attempt from an already running Windows XP VM, named "Windows XP" using this command from a Ubuntu terminal commandline: VBoxManage guestcontrol Windows\ XP exec --image c:\\program\ files\\quicken\\qw.exe --username XXXXX --password XXXXX, where XXXXX was my username and password.
  • Anderson Green
    Anderson Green almost 12 years
    Should each of these commands be run from the Windows command line or the Ubuntu command line?
  • Javier Rivera
    Javier Rivera almost 12 years
    Maybe my problem is that I use a password less account.
  • Deepak Verma
    Deepak Verma almost 12 years
    Probably... I just changed the command I ran to use your format and it did indeed run regedit.
  • Javier Rivera
    Javier Rivera almost 12 years
    Takkat have said that it doesn't work in passwordless accounts like mine. That explains why I had never been able to did it ;).
  • Deepak Verma
    Deepak Verma almost 12 years
    Pretty nice concept, although I've never really liked the seamless mode for some reason - probably because it gets confusing about keyboard navigation. But I'm tempted to try some of this out for my few Windows programs I still use, like Quicken and iTunes. @AndersonGreen: this is run from the Ubuntu commandline, and can easily be entered in a terminal for testing, then made into a script.
  • Takkat
    Takkat almost 12 years
    @JavierRivera: there is a guide to get it working with passwordless Windows accounts at the Virtual Box wiki I linked to. But this was too much Windows digging for my taste ;)
  • Javier Rivera
    Javier Rivera almost 12 years
    The workaround suggested there is to allow remote login for passwordless accounts... looks like a really dangerous idea to me ;).
  • Anderson Green
    Anderson Green over 11 years
    Should the password (being entered in the script) be the Windows login password, or the Ubuntu login password?
  • user68186
    user68186 over 9 years
    Have you tested this in an Ubuntu host?
  • Urban
    Urban over 9 years
    No, but I'm pretty sure it would work without glitches. The vbox commands are the same and so is bash.
  • muru
    muru over 9 years
    It's safer to use pgrep instead of ps | grep. The latter runs the risk of matching itself.
  • Urban
    Urban over 9 years
    Yes, you're right. I believe fixed it above using ps by adding an extra grep -v to filter away the self-match problem. I couldn't figure out how to use pgrep as you suggested in this case since the VBox name 'Windows 7' in my case is a comment argument to the process, like this: MacMini:~ urban$ ps ax | grep -v grep | grep 'Windows 7' 10874 ?? R 4:38.49 /Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM‌​.app/Contents/MacOS/‌​VirtualBoxVM --comment Windows 7 --startvm 24507412-789d-42ed-9c79-b4faf0c2d130 --no-startvm-errormsgbox but maybe you have a suggestion on this?
  • William
    William over 5 years
    Should this work in the opposite manor(running Windows as main OS and linux as virtual machine)
  • Takkat
    Takkat over 5 years
    @William: it should indeed but ATM I can't test this (no Windows hosts here). Nevertheless I think, most people use SSH to run an application in an Ubuntu guest.