how to get the session from a machine

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
ShaunHirst
Posts: 3
Joined: 29. Apr 2016, 22:26

how to get the session from a machine

Post by ShaunHirst »

I can get and launch machines from my app.

is it possible to access the session of a IMachine after the application is restarts?
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: how to get the session from a machine

Post by noteirak »

Yes, exactly the same way you got a session the first time
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
ShaunHirst
Posts: 3
Joined: 29. Apr 2016, 22:26

Re: how to get the session from a machine

Post by ShaunHirst »

Ok,

so to get a session I do GetDefaultInterface();

I then use the returned session to launch a vm

BSTR GuiName = SysAllocString(L"gui");
BSTR Environment = SysAllocString(L"");
HRESULT Ret = Machine->LaunchVMProcess( Session, GuiName, Environment, &ProgressObj );

then I restart my app.

after this find the VM

BSTR MachineName = SysAllocString( WideString( NameIn ).c_bstr() );
Virtualbox_tlb::IMachine *Machine = VBox->FindMachine( MachineName );

but if I get a session again GetDefaultInterface() i'm not able to do anything with the VM. i get a message saying the session is not locked.

I tried locking the machine with the session but that didn't work.

What am I doing wrong

Thanks in advance
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: how to get the session from a machine

Post by noteirak »

Have a look at this Java code sample https://gist.github.com/maxidor/e222a7ca0a19ebcb75f2
You'll see how we get a session for machines, how we edit settings for locked machines (using Isession::getMachine) and finally how we unlock the session (very important)
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
ShaunHirst
Posts: 3
Joined: 29. Apr 2016, 22:26

Re: how to get the session from a machine

Post by ShaunHirst »

Thanks for you help I see where you went wrong.
Post Reply