The question is how to run the application so that it is displayed inside the guest GUI? Through vboxmanage guest control is works, although the result is displayed in the CMD host.
Code: Select all
public class Main {
public static VirtualBoxManager mgr;
public static IVirtualBox vbox;
public static void main(String[] args) throws InterruptedException {
mgr = VirtualBoxManager.createInstance(null);
mgr.connect("http://localhost:18083", "User", "a12345678");
vbox = mgr.getVBox();
IMachine mach = Main.vbox.findMachine("Test");
ISession session = Main.mgr.getSessionObject();
mach.lockMachine(session, LockType.Shared);
IGuestSession guestSession = null;
try {
guestSession = session.getConsole().getGuest().createSession("TestUser", "changeme", null,null);
guestSession.waitFor(1l, 30 * 1000l);
System.out.println("GuestSessionStatus: " + guestSession.getStatus());
IProcess process = guestSession.processCreate("C:\\Windows\\System32\\tasklist.exe", null,null, Collections.singletonList(ProcessCreateFlag.Profile), 0L);
IGuestProcess processa = IGuestProcess.queryInterface(process);
System.out.println("firstProcessStatus: " + processa.getStatus().toString());
processa.waitForArray(Collections.singletonList(ProcessWaitForFlag.StdOut), 0L);
ProcessStatus processStatus = processa.getStatus();
System.out.println("Process Status: " + processStatus.toString() + "|value: " + processStatus.value() + "|name" + processStatus.name());
System.out.println("GuestSessionUser: " + guestSession.getUser());
System.out.println("lastProcessStatus: " + processa.getStatus());
System.out.println("statusSessionLast: " + guestSession.getStatus());
System.out.println("processGet: " + guestSession.processGet(1L).toString());
} finally {
guestSession.close();
session.unlockMachine();
mgr.cleanup();
mgr.disconnect();
}
}
}
Code: Select all
GuestSessionStatus: Started
firstProcessStatus: Started
Process Status: Started|value: 100|nameStarted
GuestSessionUser: TestUser
lastProcessStatus: Started
statusSessionLast: Started
Exception in thread "main" org.virtualbox_7_0.VBoxException: VirtualBox error: rc=0x80070057 No process with PID 1 found (0x80070057)
at org.virtualbox_7_0.IGuestSession.processGet(IGuestSession.java:2092)
at Main.main(Main.java:38)
Caused by: org.virtualbox_7_0.jaxws.RuntimeFaultMsg: VirtualBox error: rc=0x80070057 No process with PID 1 found (0x80070057)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:135)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy35.iGuestSessionProcessGet(Unknown Source)
at org.virtualbox_7_0.IGuestSession.processGet(IGuestSession.java:2083)
... 1 more