Page 1 of 1

Using the SDK to launch programs in a guest?

Posted: 13. Dec 2012, 04:04
by SpaceRook
Hello,
I am on a Windows host using Ubuntu as a guest. I would like to write a Java program that runs in Windows and launches a program in Ubuntu. For example, the user clicks a button in the Windows Java program and Firefox launches in Ubuntu.

According to the APIs, this should be possible. However, I have never been able to get it to work. Does anyone have any ideas? Below is my code:

Code: Select all

String machineName = "MyMachine";
String url = "http://localhost:18083";
String user = "";
String passwd = "";

VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
mgr.connect(url, user, passwd);
IVirtualBox vbox = mgr.getVBox();
System.out.println("Running VirtualBox version " + vbox.getVersion());

IMachine machine = vbox.findMachine(machineName);
ISession session = mgr.getSessionObject();
machine.lockMachine(session,  LockType.Shared);
IConsole console = session.getConsole();
IGuest guest = console.getGuest();

IGuestSession guestSession = guest.createSession("bob","password", "", "");
guestSession.processCreate("/usr/bin/firefox", null, null, null, 0L);

session.unlockMachine();
The error that appears is:

Code: Select all

Exception in thread "main" org.virtualbox_4_2.VBoxException: VirtualBox error: The   session is not locked (session state: Unlocked) (0x8000FFFF)
at org.virtualbox_4_2.ISession.getConsole(ISession.java:145)
at Test1.main(Test1.java:27)
I've tried a few different things with locks and sessions, but they all result in some type of error. All I need is a simple "HelloWorld"-type example of a Host launching a program in the guest. Any help appreciated.

Re: Using the SDK to launch programs in a guest?

Posted: 13. Dec 2012, 12:39
by noteirak
did you try with LockType.Write?

Re: Using the SDK to launch programs in a guest?

Posted: 14. Dec 2012, 01:45
by SpaceRook
Hi,
I was able to solve the problem. In the line:

Code: Select all

guestSession.processCreate("/usr/bin/firefox", null, null, null, 0L);
....the third parameter needs to take the environment variable DISPLAY set to :0 (or whatever your display screen is).

This post can be marked as SOLVED.

Re: Using the SDK to launch programs in a guest?

Posted: 21. Jan 2013, 13:18
by StefanoV
Hi SpaceRook,
could you please post your solution?
I'm having a similar issue and still not able to launch
an application inside the guest.

Thanks