如何列出注册到Msvm_ComputerSystem类的WMI事件。我创建了一个vm并且有一个事件来注册poweronEvent。现在我要列出已注册的事件。请帮助。
答案 0 :(得分:0)
您可以尝试使用此代码 - 基于ObjectQuery
类
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());
}