I am having some issues in accessing the cableConnected property with C# for a VM. The goal is to be able to disconnect the cable upon a certain event happening. However, I am stuck on simply trying to perform this action whenever my application is run. I am currently using VirtualBox (and API) v4.2.16 on Windows 7, and would really appreciate some help in pointing out what is wrong with this application. Whenever I run this application I get the error "The machine 'test' is already locked for a session (or being unlocked)". The VM is running at the point which I run my application just fyi. I am very new to C#, so please be patient with me. The code is as follows:
- Code: Select all Expand viewCollapse view
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
using VirtualBox;
namespace AdapterDisableTest
{
class Program
{
static void Main(string[] args)
{
VirtualBoxClient vBoxClient = new VirtualBoxClient();
var machine = vBoxClient.VirtualBox.FindMachine("test");
machine.LockMachine(vBoxClient.Session, LockType.LockType_Write);
machine.GetNetworkAdapter(0).SetProperty("cableConnected", "0");
vBoxClient.Session.UnlockMachine();
Console.WriteLine(machine.GetNetworkAdapter(0).GetProperty("Cable Connected"));
Console.ReadLine();
}
}
}