Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

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 Virtual Box 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>"
    
  • Run an application in the VM

    VBoxManage --nologo guestcontrol "<Name_of_VM>" execute --image "C:\\full\\path\\to\\program.exe" --username windowsuser --password password --wait-exit --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.

share|improve this answer
    
Should each of these commands be run from the Windows command line or the Ubuntu command line? –  Anderson Green Jun 21 '12 at 16:50
    
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. –  Marty Fried Jun 21 '12 at 17:39
    
Should the password (being entered in the script) be the Windows login password, or the Ubuntu login password? –  Anderson Green Dec 23 '12 at 19:20
    
It is the windows password you need as you are likely logged in to Ubuntu, and starting a VM should not require root access. Note that you need a Windows password and login for this to work. –  Takkat Dec 23 '12 at 19:24
add comment

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.

share|improve this answer
    
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 Jun 21 '12 at 0:24
    
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 Jun 21 '12 at 0:28
    
Could the inverse be done using guest additions, then? –  Anderson Green Jun 21 '12 at 0:35
    
Also, are you referring to the Windows startup folder or the Ubuntu startup applications list? –  Anderson Green Jun 21 '12 at 0:36
    
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. –  Marty Fried Jun 21 '12 at 0:42
show 2 more comments

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.

share|improve this answer
    
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. –  Marty Fried Jun 21 '12 at 16:30
    
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. –  Marty Fried Jun 21 '12 at 16:50
    
Maybe my problem is that I use a password less account. –  Javier Rivera Jun 21 '12 at 17:14
    
Probably... I just changed the command I ran to use your format and it did indeed run regedit. –  Marty Fried Jun 21 '12 at 17:28
    
Takkat have said that it doesn't work in passwordless accounts like mine. That explains why I had never been able to did it ;). –  Javier Rivera Jun 21 '12 at 17:30
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.