More FSO Functioality that doesnt apear in System.IO

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using the FileSystemObject I can, at runtime find out which drive letter is asigned to the CD Rom Drive

Dim Fso As New Scripting.FileSystemObject
For Each Drive As Scripting.Drive In Fso.Drives
If Drive.DriveType = Scripting.DriveTypeConst.CDRom Then
MsgBox("Your CD Rom drive is: " & Drive.Path)
Exit For
End If
Next

But I cannot find a way to get this info out of the System.IO namespace

Dim objDir As System.IO.DirectoryInfo
For Each s As String In System.IO.Directory.GetLogicalDrives()
objDir = New System.IO.DirectoryInfo(s)
'Cant get the drive type from the DirectoryInfo Object
Next

I would prefer not to use the FileSystemObject if I can avoid it.
Please could someone point me in the right direction.

Ben
 
Ben Reese said:
Using the FileSystemObject I can, at runtime find out which drive letter is asigned to the CD Rom Drive

Dim Fso As New Scripting.FileSystemObject
For Each Drive As Scripting.Drive In Fso.Drives
If Drive.DriveType = Scripting.DriveTypeConst.CDRom Then
MsgBox("Your CD Rom drive is: " & Drive.Path)
Exit For
End If
Next

But I cannot find a way to get this info out of the System.IO namespace

Dim objDir As System.IO.DirectoryInfo
For Each s As String In System.IO.Directory.GetLogicalDrives()
objDir = New System.IO.DirectoryInfo(s)
'Cant get the drive type from the DirectoryInfo Object
Next

I would prefer not to use the FileSystemObject if I can avoid it.
Please could someone point me in the right direction.

Ben

WMI has all the functionality now :


ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From
Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();

foreach ( ManagementObject mo in queryCollection)
{
switch (int.Parse( mo["DriveType"].ToString()))
{
case 2: //removable drives
break;
case 3: //Local drives
break;
case 4: //Network drives
break;
case 5: //CD rom drives
break;
}
}


HTH

Yves
 
Thanks Yves this looks good

but where can I find a list of valid "PropertyValues" for the ManagementObject?

phoenix said:
Ben Reese said:
Using the FileSystemObject I can, at runtime find out which drive letter is asigned to the CD Rom Drive

Dim Fso As New Scripting.FileSystemObject
For Each Drive As Scripting.Drive In Fso.Drives
If Drive.DriveType = Scripting.DriveTypeConst.CDRom Then
MsgBox("Your CD Rom drive is: " & Drive.Path)
Exit For
End If
Next

But I cannot find a way to get this info out of the System.IO namespace

Dim objDir As System.IO.DirectoryInfo
For Each s As String In System.IO.Directory.GetLogicalDrives()
objDir = New System.IO.DirectoryInfo(s)
'Cant get the drive type from the DirectoryInfo Object
Next

I would prefer not to use the FileSystemObject if I can avoid it.
Please could someone point me in the right direction.

Ben

WMI has all the functionality now :


ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From
Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();

foreach ( ManagementObject mo in queryCollection)
{
switch (int.Parse( mo["DriveType"].ToString()))
{
case 2: //removable drives
break;
case 3: //Local drives
break;
case 4: //Network drives
break;
case 5: //CD rom drives
break;
}
}


HTH

Yves
 
Also

Is there no Enumeration that maps to the "DriveType"

Ben

phoenix said:
Ben Reese said:
Using the FileSystemObject I can, at runtime find out which drive letter is asigned to the CD Rom Drive

Dim Fso As New Scripting.FileSystemObject
For Each Drive As Scripting.Drive In Fso.Drives
If Drive.DriveType = Scripting.DriveTypeConst.CDRom Then
MsgBox("Your CD Rom drive is: " & Drive.Path)
Exit For
End If
Next

But I cannot find a way to get this info out of the System.IO namespace

Dim objDir As System.IO.DirectoryInfo
For Each s As String In System.IO.Directory.GetLogicalDrives()
objDir = New System.IO.DirectoryInfo(s)
'Cant get the drive type from the DirectoryInfo Object
Next

I would prefer not to use the FileSystemObject if I can avoid it.
Please could someone point me in the right direction.

Ben

WMI has all the functionality now :


ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From
Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();

foreach ( ManagementObject mo in queryCollection)
{
switch (int.Parse( mo["DriveType"].ToString()))
{
case 2: //removable drives
break;
case 3: //Local drives
break;
case 4: //Network drives
break;
case 5: //CD rom drives
break;
}
}


HTH

Yves
 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp

and similar pages offer an overview of all properties. Also clicking on the
different properties on that page will give you the corresponding enums. I
don't know if you can get them directly from inside C# though.

HTH

Yves

Ben Reese said:
Thanks Yves this looks good

but where can I find a list of valid "PropertyValues" for the ManagementObject?

phoenix said:
Ben Reese said:
Using the FileSystemObject I can, at runtime find out which drive
letter
is asigned to the CD Rom Drive
Dim Fso As New Scripting.FileSystemObject
For Each Drive As Scripting.Drive In Fso.Drives
If Drive.DriveType = Scripting.DriveTypeConst.CDRom Then
MsgBox("Your CD Rom drive is: " & Drive.Path)
Exit For
End If
Next

But I cannot find a way to get this info out of the System.IO namespace

Dim objDir As System.IO.DirectoryInfo
For Each s As String In System.IO.Directory.GetLogicalDrives()
objDir = New System.IO.DirectoryInfo(s)
'Cant get the drive type from the DirectoryInfo Object
Next

I would prefer not to use the FileSystemObject if I can avoid it.
Please could someone point me in the right direction.

Ben

WMI has all the functionality now :


ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From
Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();

foreach ( ManagementObject mo in queryCollection)
{
switch (int.Parse( mo["DriveType"].ToString()))
{
case 2: //removable drives
break;
case 3: //Local drives
break;
case 4: //Network drives
break;
case 5: //CD rom drives
break;
}
}


HTH

Yves
 
Back
Top