Beispiel #1
0
        public static DriveInfo ReadLogicalDiskInfo()
        {
            DriveInfo drives = new DriveInfo();

            try
            {
                ManagementObjectSearcher    searcher = new ManagementObjectSearcher("SELECT DeviceID, Description, FileSystem, FreeSpace, Size FROM Win32_LogicalDisk");
                Dictionary <string, string> data     = new Dictionary <string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    DiskInfo di = new DiskInfo();

                    if (queryObj["DeviceID"] != null)
                    {
                        di.DeviceID = queryObj["DeviceID"].ToString();
                    }

                    if (queryObj["Description"] != null)
                    {
                        di.DriveType = queryObj["Description"].ToString();
                    }

                    if (queryObj["FileSystem"] != null)
                    {
                        di.FileSystem = queryObj["FileSystem"].ToString();
                    }

                    if (queryObj["FreeSpace"] != null)
                    {
                        di.FreeSpace = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["FreeSpace"].ToString()));
                    }

                    if (queryObj["Size"] != null)
                    {
                        di.Size = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["Size"].ToString()));
                    }

                    drives.Drives.Add(di);
                }
            }
            catch (Exception e)
            {
            }
            finally
            { }

            return(drives);
        }
Beispiel #2
0
        public static DriveInfo ReadLogicalDiskInfo()
        {
            DriveInfo drives = new DriveInfo();
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT DeviceID, Description, FileSystem, FreeSpace, Size FROM Win32_LogicalDisk");
                Dictionary<string, string> data = new Dictionary<string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    DiskInfo di = new DiskInfo();

                    if (queryObj["DeviceID"] != null)
                    {
                        di.DeviceID = queryObj["DeviceID"].ToString();
                    }

                    if (queryObj["Description"] != null)
                    {
                        di.DriveType = queryObj["Description"].ToString();
                    }

                    if (queryObj["FileSystem"] != null)
                    {
                        di.FileSystem = queryObj["FileSystem"].ToString();
                    }

                    if (queryObj["FreeSpace"] != null)
                    {
                        di.FreeSpace = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["FreeSpace"].ToString()));
                    }

                    if (queryObj["Size"] != null)
                    {
                        di.Size = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["Size"].ToString()));
                    }

                    drives.Drives.Add(di);
                }
            }
            catch (Exception e)
            {

            }
            finally
            { }

            return drives;
        }