Example #1
0
        public static Dictionary <string, string> GetMountPointVolumeIDMappings(out Exception ex)
        {
            Dictionary <string, string> mountPointVolumeIdMappings = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            ex = null;
            ManagementObjectCollection mountPointToVolumeMappings = WMIUtil.GetManagementObjectCollection("Win32_MountPoint", "\\ROOT\\CIMV2", out ex);

            if (mountPointToVolumeMappings == null)
            {
                return(null);
            }
            ex = Util.HandleExceptions(delegate
            {
                using (ManagementObjectCollection mountPointToVolumeMappings = mountPointToVolumeMappings)
                {
                    foreach (ManagementBaseObject managementBaseObject in mountPointToVolumeMappings)
                    {
                        ManagementObject managementObject = (ManagementObject)managementBaseObject;
                        using (managementObject)
                        {
                            string input   = managementObject.GetPropertyValue("Volume").ToString();
                            string input2  = managementObject.GetPropertyValue("Directory").ToString();
                            string pattern = "\"(.*)\"";
                            Match match    = Regex.Match(input, pattern);
                            Match match2   = Regex.Match(input2, pattern);
                            if (match.Success && match2.Success)
                            {
                                mountPointVolumeIdMappings.Add(Util.RemoveEscapeCharacters(match2.Groups[1].Value), Util.RemoveEscapeCharacters(match.Groups[1].Value));
                            }
                        }
                    }
                }
            });
            return(mountPointVolumeIdMappings);
        }
Example #2
0
        public static ManagementObjectCollection GetEncryptableVolumes()
        {
            Exception ex;

            return(WMIUtil.GetManagementObjectCollection("Win32_EncryptableVolume", "\\ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption", out ex));
        }