Device Type

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Is there some way for me to identify if a particular drive is a CDROM or a
Floppy drive or a local or network drive?
 
Jim Heavey said:
Is there some way for me to identify if a particular drive is a CDROM
or a Floppy drive or a local or network drive?

Have a look at API function GetDriveType

VS 2003:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB/fileio/base/getdrivetype.htm

(see hints in signature)



--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.1033" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
tools -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.
 
Hello,

Jim Heavey said:
Is there some way for me to identify if a particular drive is a CDROM or a
Floppy drive or a local or network drive?

Set a reference to System.Management.dll

\\\
Imports System.Management
..
..
..
Public Enum DriveType
Unknown = 0
NoRootDirectory = 1
RemoveableDisk = 2
LocalDisk = 3
NetworkDrive = 4
CompactDisk = 5
RamDisk = 6
End Enum

Public Function GetDriveType(ByVal strDrive As String) As DriveType
strDrive = "Win32_LogicalDisk='" & strDrive.Substring(0, 2) & "'"
Dim moDisk As ManagementObject = New ManagementObject(strDrive)
Return _
DirectCast( _
[Enum].Parse(GetType(DriveType),
moDisk("DriveType").ToString()), _
DriveType _
)
End Function
..
..
..
Dim astrDrives() As String = Environment.GetLogicalDrives()
Dim strDrive As String
For Each strDrive In astrDrives
MessageBox.Show( _
"Drive: " & strDrive & ControlChars.NewLine & _
"Type: " & GetDriveType(strDrive).ToString() _
)
Next strDrive
///

HTH,
Herfried K. Wagner
 
Thanks, works like a champ!!!!!

Herfried K. Wagner said:
Hello,

Jim Heavey said:
Is there some way for me to identify if a particular drive is a CDROM or a
Floppy drive or a local or network drive?

Set a reference to System.Management.dll

\\\
Imports System.Management
.
.
.
Public Enum DriveType
Unknown = 0
NoRootDirectory = 1
RemoveableDisk = 2
LocalDisk = 3
NetworkDrive = 4
CompactDisk = 5
RamDisk = 6
End Enum

Public Function GetDriveType(ByVal strDrive As String) As DriveType
strDrive = "Win32_LogicalDisk='" & strDrive.Substring(0, 2) & "'"
Dim moDisk As ManagementObject = New ManagementObject(strDrive)
Return _
DirectCast( _
[Enum].Parse(GetType(DriveType),
moDisk("DriveType").ToString()), _
DriveType _
)
End Function
.
.
.
Dim astrDrives() As String = Environment.GetLogicalDrives()
Dim strDrive As String
For Each strDrive In astrDrives
MessageBox.Show( _
"Drive: " & strDrive & ControlChars.NewLine & _
"Type: " & GetDriveType(strDrive).ToString() _
)
Next strDrive
///

HTH,
Herfried K. Wagner
 
Back
Top