How do you detect programmatically [c#] if a disk is offline?

1k views Asked by At

In Windows 'Disk Management' there is a property of a drive that is 'online/offline'. How can I expose this property in for remote hardware? I know were it is not; it is not in: win32_logicaldisk, win32_diskdrive, CIM_LogicalDisk, & CIM_LogicalDevice nor is it in System.IO.DriveInfo

2

There are 2 answers

0
Angelom On

If you are using c# you should be able to get all this information through WMI.

0
Greg On

Do you mean something like this:

DriveInfo drive = GetDrives();

foreach(DriveInfo d in drive)
{
    Console.WriteLine("Drive {0}", d.Name);
    Console.WriteLine" File Type: {0}", d.DriveType);

    if(d.IsReady == true)
    {
         Console.WriteLine(" Volume Label: {0}", d.VolumeLabel);
    }
}

You can find a great example, straight off MSDN. Essentially if it detects an avaliable drive that is Ready it will display information about it. If not, then it won't display anything.

You can obviously modify this even further.

You can also implement Powershell or WMI Scripts from C# to accomplish the task. You have a lot of flexibility in this instance.

Hope that helps.