Page 1 of 1

Virtual machine is not mutable

Posted: 28. Oct 2017, 14:36
by ahmed1
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

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

Re: Virtual machine is not mutable

Posted: 20. Nov 2017, 20:49
by noteirak
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.