Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Enumerate Computer Drives
 

Vbscript / Operating System / Enumerate Computer Drives

List the drives attached to a computer and display the type and capacity of each.


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    strFreeSpace = byteValue(objDisk.Freespace)
    strTotalSpace = byteValue(objDisk.Size)

intDrivetype = objDisk.DriveType

Select Case intDriveType

Case 2
strDriveType = "Floppy Drive"

Case 3
strDriveType = "Hard Drive"

Case 4
strDriveType = "Network Drive"

Case 5
strDriveType = "CDROM Drive"

End Select

    pctFreeSpace = int(100 * (objDisk.Freespace / objDisk.Size))
    Wscript.Echo "Drive Letter: " & objDisk.DeviceId & vbCRLF & "Drive Type: " & strDriveType & vbCRLF & "Drive Size: " & strTotalSpace & vbCRLF & "Free Space: " & strFreeSpace & " (" & pctFreeSpace & "%)"
Next

Function byteValue(val)

If val > 1000 Then

val = val/1024
unit = " KB"

If val > 1000 Then

val = val/1024
unit = " MB"

If val > 1000 Then

val = val/1024
unit = " GB"

If val > 1000 Then

val = val/1024
unit = " TB"

End If
End If
End If
End If

byteValue = int(val) & unit

End function





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
          - Add Remove Windows Server 2003 Components
          - Add Remove Windows Vista Components
          - Add Remove Windows Xp Components
          - Autologon And Runonce
          - Change Display Resolution
          - Change Location I386 Setup Files
          - Change Offline Folder Cache Location
          - Dell Bios Set Boot Device Order
          - Dell Bios Set Configuration Settings
          - Dell Bios View Configuration Settings
          - Dell Bios View Device Boot Order
          - Disable Vista User Account Control
          - Enumerate Cd Drives
          - Enumerate Computer Drives
          - Enumerate Disk Volumes
          - Enumerate Registry Keys
          - Flush Remote Dns Cache
          - Get Machine Hardware Model
          - Read Registry Key
          - Rename Computer
          - Rename Dell Machine By Service Tag
          - Set Internet Explorer Homepage
          - Set Random Desktop Wallpaper On Startup
          - Start And Stop A Service
          - Windows Login Timer
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers