By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,381 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,381 IT Pros & Developers. It's quick & easy.

estimating drive types

P: n/a
Hello,

I just got my drives through Directory.GetLogicalDrives() but now I want to
distinguesh between real harddisk, floppy, CD-Rom or network drive. I didn't
find any good idea for that.

Can anyone help me with that?

Thanks

Matthias
Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,
You can import GetDriveType from kernel32.dll
[DllImport("kernel32")]
static extern int GetDriveType(string path);

it returns the drive type :
const int DRIVE_CDROM = 5;
const int DRIVE_FIXED = 3;
const int DRIVE_NO_ROOT = 1;
const int DRIVE_REMOTE = 4;
const int DRIVE_REMOVABLE = 2;

Matthias Heise wrote:
Hello,

I just got my drives through Directory.GetLogicalDrives() but now I want to
distinguesh between real harddisk, floppy, CD-Rom or network drive. I didn't
find any good idea for that.

Can anyone help me with that?

Thanks

Matthias

Nov 17 '05 #2

P: n/a
Hi,
You can import GetDriveType from kernel32.dll
[DllImport("kernel32")]
static extern int GetDriveType(string path);

it returns the drive type :
const int DRIVE_CDROM = 5;
const int DRIVE_FIXED = 3;
const int DRIVE_NO_ROOT = 1;
const int DRIVE_REMOTE = 4;
const int DRIVE_REMOVABLE = 2;
Matthias Heise wrote:
Hello,

I just got my drives through Directory.GetLogicalDrives() but now I want to
distinguesh between real harddisk, floppy, CD-Rom or network drive. I didn't
find any good idea for that.

Can anyone help me with that?

Thanks

Matthias

Nov 17 '05 #3

P: n/a
Thanks,

but now another problem. When I'm trying to get the subdirectories with
Dir.GetDirectories() the application chrashes when accessing a CD-Rom with
no media in it.

Is there any method to test if a media within the drive is present or if a
network drive is realy mounted?

Thanks again

Matthias
Nov 17 '05 #4

P: n/a
I have created this small console application using WMI with a WQL statement
to retrieve a list of drives.

using System;
using System.Management;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);

foreach (ManagementObject logicalDisk in searcher.Get())
{
Console.WriteLine("{0} has a DriveType of {1}",
logicalDisk["Name"], logicalDisk["DriveType"]);
}
Console.Read();
}
}
}

Gabriel Lozano-Morán
Nov 17 '05 #5

P: n/a
Forgot to mention the drivetypes:

0 -> Unknown
1 -> No Root Directory
2 -> Removable Disk
3 -> Local Disk
4 -> Network Drive
5 -> Compact Disc
6 -> RAM Disk

Search on the MSDN for the string "Win32_LogicalDisk" for more info.

Gabriel Lozano-Morán
Nov 17 '05 #6

P: n/a
thanks

works fine.

Matthias
Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.