Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drive information...
Message
From
25/07/2003 05:26:37
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00813365
Message ID:
00813422
Views:
6
Joe,

One alternative you could look at is WMI available from the following namespace.
using System.Management;
This allows you to query the Win32_LogicalDisk WMI class and return a *huge* amount of information using the classlibrary using query language. For example, to get a collection of drives you could do the following.
using System;
using System.Management;

namespace ConsoleApplication2
{
   class Class1
   {
      static void Main(string[] args)
      {
         ObjectQuery objectQuery = new ObjectQuery("select * from Win32_LogicalDisk");
         ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery);

         foreach (ManagementObject DiskDrive in searcher.Get())
         {
            Console.WriteLine("Drive = " + DiskDrive["Name"] + " FileSystem = " + DiskDrive["FileSystem"]);
         }
      }
   }
}
Now if you only wanted NTFS drives you could alter the query to look something like this.
select * from Win32LogicalDisk where FileSystem IS NOT "NTFS"
If you want to get at the Win32_LogicalDisk class for a specific drive then you can use the following.
ManagementObject HardDrive = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
HardDrive.Get();

Console.WriteLine("Drive C: Logical Disk Size = " + HardDrive["Size"] + " bytes");
The following represent the members available to the Win32_LogicalDisk class.
  uint16 Access;
  uint16 Availability;
  uint64 BlockSize;
  string Caption;
  boolean Compressed;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  string Description;
  string DeviceID;
  uint32 DriveType;
  boolean ErrorCleared;
  string ErrorDescription;
  string ErrorMethodology;
  string FileSystem;
  uint64 FreeSpace;
  datetime InstallDate;
  uint32 LastErrorCode;
  uint32 MaximumComponentLength;
  uint32 MediaType;
  string Name;
  uint64 NumberOfBlocks;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string ProviderName;
  string Purpose;
  boolean QuotasDisabled;
  boolean QuotasIncomplete;
  boolean QuotasRebuilding;
  uint64 Size;
  string Status;
  uint16 StatusInfo;
  boolean SupportsDiskQuotas;
  boolean SupportsFileBasedCompression;
  string SystemCreationClassName;
  string SystemName;
  boolean VolumeDirty;
  string VolumeName;
  string VolumeSerialNumber
When you start looking beyond the Win32LogicalDisk class you will see there is a whole host of information you can get at like Win32_MappedLogicalDisk.

The following link is a list of the WMI classes available for use in your applications. Obviously the target OS and security is going to play a part in what you can and cannot do but WMI is a fantastic resource with huge depth.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_ntlogevent.asp
Previous
Reply
Map
View

Click here to load this message in the networking platform