Virtual machine is not mutable

Discussion about using the VirtualBox API, Tutorials, Samples.

Virtual machine is not mutable

Postby ahmed1 » 28. Oct 2017, 14:36

Hi,
i am using virtual box 5.1.26
i am developing using C# using COM. i am trying to do many actions which require to lock the VM as per my under standing for example (start monitoring, vm save state, updating cableconnected state)

i am using the following code
Code: Select all   Expand viewCollapse view
private void btn_start_monitor_Click(object sender, EventArgs e)
            {


                if (m.State == MachineState.MachineState_PoweredOff|| m.State==MachineState.MachineState_Saved)
                {
                    Session session = new VirtualBox.Session();
                   
                    ///this can only done if the machine is powered of
                    ///
                   
                        m.LockMachine(session, VirtualBox.LockType.LockType_Null);
                        INetworkAdapter NetAdapter = m.GetNetworkAdapter((uint)0);
                        NetAdapter.TraceEnabled = 1;
                        NetAdapter.TraceFile = "c:\\logs\\NTlog.pcap";
                                   

                }
                else
                    MessageBox.Show("the virtual machine " + m.Name + "must be powered of or saved first");
}

but unfortunately whatever was the state of the machine it gives me error message
The machine is not mutable, saved or running (state is ....)
then the vm state become aborted

any advise
thanks
ahmed1
 
Posts: 5
Joined: 21. Oct 2017, 18:57
Primary OS: MS Windows 10
VBox Version: OSE other
Guest OSses: windows 2008

Re: Virtual machine is not mutable

Postby noteirak » 20. Nov 2017, 20:49

The message means you're not holding a lock on the machine. your code doesn't show what `m` is, but I'm guessing the machine. In any case, the lock you use (Null) is not correct, and should be Shared.
Finally, you need to use the IMachine object from the session object. The original machine object is not made mutable.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 1 guest