Using the SDK to launch programs in a guest?

Discussions related to using VirtualBox on Windows hosts.
Post Reply
SpaceRook
Posts: 3
Joined: 10. Dec 2012, 09:19

Using the SDK to launch programs in a guest?

Post 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.
noteirak
Site Moderator
Posts: 5231
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

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

Post by noteirak »

did you try with LockType.Write?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
SpaceRook
Posts: 3
Joined: 10. Dec 2012, 09:19

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

Post 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.
StefanoV
Posts: 1
Joined: 21. Jan 2013, 13:12

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

Post 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
Post Reply