Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

The simpliest way is to first add a reference to Interop.Scripting.dll in your project.

Then

       Dim fso As New Scripting.FileSystemObject()
       Dim drv As Scripting.Drive
       Dim drvInfo As String

       For Each drv In fso.Drives
           'get drive letter
           drvInfo = drv.DriveLetter & ": "

           If Not drv.IsReady Then
               'get drive type
               Select Case drv.DriveType
                   Case Scripting.DriveTypeConst.Removable
                       drvInfo &= "3-1/2 Floppy Drive"
                       'drvInfo &= "Removable Drive"
                   Case Scripting.DriveTypeConst.CDRom
                       drvInfo &= "CD Rom Drive"
                   Case Scripting.DriveTypeConst.RamDisk
                       drvInfo &= "Ram Disk"
                   Case Scripting.DriveTypeConst.Remote
                       drvInfo &= "Network Drive"
                   Case Scripting.DriveTypeConst.UnknownType
                       drvInfo &= "Unknown Drive"
               End Select

               If drv.DriveType <> Scripting.DriveTypeConst.Fixed Then
                   sysInfo(item, 0) = drvInfo
                   sysInfo(item, 1) = " "
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = " "
                   item += 1
               End If

           ElseIf drv.IsReady Then
               'get drive type
               Select Case drv.DriveType
                   Case Scripting.DriveTypeConst.Removable
                       drvInfo &= "3-1/2 Floppy Drive"
                       'drvInfo &= "Removable Drive"
                   Case Scripting.DriveTypeConst.CDRom
                       drvInfo &= "CD Rom Drive"
                   Case Scripting.DriveTypeConst.RamDisk
                       drvInfo &= "Ram Disk"
                   Case Scripting.DriveTypeConst.Remote
                       drvInfo &= "Network Drive"
                   Case Scripting.DriveTypeConst.UnknownType
                       drvInfo &= "Unknown Drive"
                   Case Scripting.DriveTypeConst.Fixed
                       drvInfo &= "Local Drive"
               End Select
               If drv.DriveType <> Scripting.DriveTypeConst.Fixed Then
                   sysInfo(item, 0) = drvInfo
                   sysInfo(item, 1) = drv.VolumeName
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = " "
                   item += 1

               Else 'hard drive information
                   sysInfo(item, 0) = drvInfo
                   sysInfo(item, 1) = "Volume Name: " & drv.VolumeName
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = "Total Size: " & Math.Round(Val(drv.TotalSize) / 1000000000, 2) & " GB"
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = "Free Space: " & Math.Round(Val(drv.FreeSpace) / 1000000000, 2) & " GB"
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = "Used Space: " & Math.Round((Val(drv.TotalSize) - Val(drv.FreeSpace)) / 1000000000, 2) & " GB"
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = "File System: " & drv.FileSystem
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = "Serial Number: " & drv.SerialNumber
                   item += 1
                   sysInfo(item, 0) = " "
                   sysInfo(item, 1) = " "
                   item += 1
               End If
           End If

 

sysInfo(item, 1) is a 2D array I use to populate a listview, but of course, you can use anything other method of displaying the drive info.

 

Hope that gives you an idea

Dan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

thanks for your answer, but...

I can't find Interop.Scripting.dll, is a file or a namespace, can you tell me the full namespace/file name??

 

Bye,

Ronq.

  • *Experts*
Posted

From the VS Studio menu click Project, Add Reference, Com, Microsoft Scripting DLL. Microsoft Scripting DLL is Interop.Scripting.dll.

 

Hope that helps

Dan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...