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;
    }
Example #2
0
 public ManagementObjectCollection Query(string query)
 {
     if (this._mo == null)
     {
         throw new HyperVException("ManagedElement not initialized");
     }
     return(WMIUtils.Query(this._mo.Scope, query));
 }
Example #3
0
    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);
    }
Example #4
0
    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);
    }
Example #5
0
 public static ManagementObject QueryFirst(ManagementScope scope, string query)
 {
     return(WMIUtils.GetFirstElement(WMIUtils.Query(scope, query)));
 }
Example #6
0
 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);
 }