Virtual machine is not mutable

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
ahmed1
Posts: 5
Joined: 21. Oct 2017, 18:57
Primary OS: MS Windows 10
VBox Version: OSE other
Guest OSses: windows 2008

Virtual machine is not mutable

Post 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
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: Virtual machine is not mutable

Post 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.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply