WMI -> Hyper-V control

I am trying to use the WMI to do stuff with my virtual machines.

I am getting an "Invalid Class" error no matter what I do.

It's when I try to loop through the vmCollection. Any tips on what i'm doing wrong would be much appreciated.

ManagementScope manScope = new ManagementScope(@"\\.\root\virtualization"); ObjectQuery queryObj = new ObjectQuery("SELECT * FROM Msvm_ComputerSystem"); ManagementObjectSearcher vmSearcher; ManagementObjectCollection vmCollection; public Form1() { InitializeComponent(); vmSearcher = new ManagementObjectSearcher(manScope, queryObj); vmCollection = vmSearcher.Get(); foreach (ManagementObject vm in vmCollection) { txtVM.Text += "Name:" + vm["ElementName"].ToString(); txtVM.Text += Environment.NewLine; txtVM.Text += "Status:" + vm["EnabledState"].ToString(); txtVM.Text += Environment.NewLine; txtVM.Text += "Description:" + vm["Description"].ToString(); txtVM.Text += Environment.NewLine; } }

Category:c# Time:2017-12-01 Views:2
Tags: hyper v wmi

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 1.320 (s). 13 q(s)