C++ COM API IGuest->CreateSession/ProcessCreate

Discussion about using the VirtualBox API, Tutorials, Samples.
syncovery
Posts: 11
Joined: 23. Dec 2016, 11:42

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by syncovery »

I could not ProcessCreate on XP virtual machine,
so I installed Win7 with the same problem.

I'm running on Win 10.
pentagonik
Oracle Corporation
Posts: 283
Joined: 19. May 2008, 16:09
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Too many to specify!
Contact:

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by pentagonik »

Just had a quick peek at the details provided.

It looks like the Guest Additions and the VBoxService inside the guest are installed correctly.

This error, however, looks like you didn't specify a password for the user you're trying to use with Guest Control:
VBoxManage.exe: error: The specified user was not able to logon on guest
VBoxManage.exe: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestSessionWrap, interface IGuestSession, callee IUnknown
VBoxManage.exe: error: Context: "WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), 30 * 1000, &enmWaitResult)" at line 938 of file VBoxManageGuestCtrl.cpp
Did you try to specify a password for the guest user and restarted the guest afterwards?
syncovery
Posts: 11
Joined: 23. Dec 2016, 11:42

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by syncovery »

Dear Pentagonik,
your notice is very crucial!

Code: Select all

Guest->CreateSession

with correct password and username provided - now makes GuestSession->ProcessCreate to start process in guest VM!

However the application on guest machine runs in hidden mode! e.g. it is visible only in Task Manager as running process and finally is killed by OS after some period.
Can you please suggest how to start application in guest machine as if it was started by user in GUI mode? In other words - visible in VirtualBox frame.

here is my code

Code: Select all

   CComSafeArray<VARIANT> aCreateFlags(2);
	aCreateFlags[0] = ProcessCreateFlag_WaitForProcessStartOnly;
	aCreateFlags[1] = ProcessCreateFlag_IgnoreOrphanedProcesses;
	p_GuestSession->ProcessCreate( SysAllocString(L"C:\\TestMonitor\\TestMonitor.exe"), NULL, NULL, aCreateFlags, 10000, p_GuestProcess );		
However it does not matter what CreateFlags i'm providing, application starts as hidden and eventually disappears.

thank you very much!!!!
Max to you too!!!
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by noteirak »

pentagonik saved the day :) thank you to him - I completely skipped that line.

As for the program not starting on the desktop, that is because the guest session initiated by VirtualBox is NOT the same as yours GUI one. It is a different, independant user session (context if you wish) and by default will not mix.
This is the same kind of issue as showing a GUI application in the GUI when started from Task Manager.
I personally do not know how to solve it on Windows...
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
syncovery
Posts: 11
Joined: 23. Dec 2016, 11:42

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by syncovery »

Hi Max,

after ProcessCreate i'm doing

Code: Select all

ProcessWaitResult aReason;
rc = GuestProcess->WaitFor( ProcessWaitForFlag_Terminate, 30000, &aReason );
and the application appears in VBox GUI frame for about 5 seconds - can see it my own eyes.
But afterwards it is killed by OS. In the same time my GuestProcess->WaitFor still waits for 30 seconds to complete.
If i use ProcessWaitForFlag_Start flag, then my GuestProcess->WaitFor is waiting for about 5 sec and exits, but there is no GUI application started is visible.

thank you supporting!
Attachments
ProcessCreate.jpg
ProcessCreate.jpg (84.21 KiB) Viewed 9239 times
syncovery
Posts: 11
Joined: 23. Dec 2016, 11:42

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by syncovery »

I want to add.
I made the same test on Win XP, and ProcessCreate with successful Guest->CreateSession started to work when i added implicit password in OS
for the User account. WinXP allows to have user account without password, but Guest->CreateSession logs in correctly when password provided.

but running application has the same effect as on Win 7, application starts and shuts down after 5 seconds.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: C++ COM API IGuest->CreateSession/ProcessCreate

Post by noteirak »

Can you try to start it via vboxmanage and see what happens? you would do something like this which is just a replica of what you do with the API:

Code: Select all

vboxmanage guestcontrol <vm> --username <user> --password <password> run <add more options> -- /path/to/exec arg1 arg2
See here for a detailed list of arguments
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply