public static IEnumerable <string> GetDriveLetters(ManagementScope scope) { ManagementObjectCollection logicalDisks = WMIUtils.Query(scope, "select * from Win32_logicaldisk"); try { foreach (ManagementObject managementObject1 in logicalDisks) { ManagementObject managementObject = managementObject1; try { if (managementObject1["Name"] != null) { yield return((string)managementObject1["Name"]); } } finally { if (managementObject != null) { managementObject.Dispose(); } } managementObject = (ManagementObject)null; } } finally { if (logicalDisks != null) { logicalDisks.Dispose(); } } logicalDisks = (ManagementObjectCollection)null; }
public ManagementObjectCollection Query(string query) { if (this._mo == null) { throw new HyperVException("ManagedElement not initialized"); } return(WMIUtils.Query(this._mo.Scope, query)); }
public static List <string> GetAllVolumeIDs() { List <string> stringList = new List <string>(); foreach (ManagementObject managementObject in WMIUtils.Query(WMIUtils.ConnectToServer("localhost", "", (string)null), "Select DeviceID From Win32_Volume")) { stringList.Add((string)managementObject["DeviceID"]); } return(stringList); }
public static List <string> GetMSFailoverClusterNicsIDs() { List <string> stringList = new List <string>(); using (ManagementObjectCollection objectCollection = WMIUtils.Query(WMIUtils.ConnectToServer("localhost", "", (string)null), "Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")) { foreach (ManagementObject managementObject in objectCollection) { if (string.Compare((string)managementObject["ServiceName"], "Netft", true) == 0) { string str = ((string)managementObject["SettingID"]).TrimStart("{".ToCharArray()).TrimEnd("}".ToCharArray()); stringList.Add(str); } } } return(stringList); }
public static ManagementObject QueryFirst(ManagementScope scope, string query) { return(WMIUtils.GetFirstElement(WMIUtils.Query(scope, query))); }
public static bool DoesVolumeExist(uint serialNumber) { return(0 < WMIUtils.Query(WMIUtils.ConnectToServer("localhost", (string)null, (string)null), string.Format((IFormatProvider)CultureInfo.InvariantCulture, "SELECT * FROM Win32_Volume WHERE SerialNumber='{0}'", new object[1] { (object)serialNumber })).Count); }