0

如何列出注册到 Msvm_ComputerSystem 类的 WMI 事件。我创建了一个虚拟机并有一个事件来注册poweronEvent。现在我想列出注册的事件。请帮忙。

4

1 回答 1

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());
            }
于 2012-10-04T12:23:35.820 回答