How to list the WMI events registered to Msvm_ComputerSystem class. I have created a vm and have an event to registerpoweronEvent. now i want to list the events registered. please help in this.
Asked
Active
Viewed 603 times
1 Answers
0
You can try with this code - based on ObjectQuery
class
VMState vmState = VMState.Undefined;
var connectionOptions = new ConnectionOptions();
connectionOptions.Username = userName;
connectionOptions.Password = password;
var managementScope= new ManagementScope(string.Format(@"\\{0}\root\virtualization", hostServer), connectionOptions );
manScope.Connect();
var objectQuery= new ObjectQuery("SELECT * FROM Msvm_ComputerSystem");
var managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery);
var collection = managementObjectSearcher.Get();
foreach (var managementObject in collection )
{
Console.WriteLine(managementObject["Yourkey"].ToString());
}

Aghilas Yakoub
- 28,516
- 5
- 46
- 51
-
I tried tis code but I am getting the following exception: Exception.System.Management.ManagementException was unhandled HResult=-2146233087 not found. And I did't get why u are using VMState. – Sandhya Akkasali Oct 08 '12 at 06:10