Using the SDK to launch programs in a guest?
Posted: 13. Dec 2012, 04:04
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:
The error that appears is:
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.
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();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)