c# - What to specify for Local ManagementScope -
i trying connect (locally) list of virtual machines , properties. have hacked code found, code failing connect can assume connection string wrong.
using server 2012, hyper-v
private void listvirtualmachines() { managementscope manscope = new managementscope(@"\\localhost\root\cimv2"); if (manscope.isconnected) { objectquery queryobj = new objectquery("select * msvm_computersystem"); // connect , set our search managementobjectsearcher vmsearcher = new managementobjectsearcher(manscope, queryobj); managementobjectcollection vmcollection = vmsearcher.get(); // loop through machines foreach (managementobject vm in vmcollection) { // display vm details logstring(vm["elementname"].tostring()); logstring(vm["enabledstate"].tostring()); logstring(vm["description"].tostring()); } } else { //we end here every time! logstring("cannot connect managementscope!"); } } //funct
in server 2012, msvm_computersystem in wmi namespace root\virtualization\v2
code should be:
managementscope manscope = new managementscope(@"\\.\root\virtualization\v2"); manscope.connect();
Comments
Post a Comment