Hey i'm trying to teach myself to use VBS and im trying to make a script that will allow me to bring up all the harddrives, removable decices and cd drives as such. Then show how much free space is on each drive.
Any help will be greatly appreciated. This is the code that i have come up with so far. (not sure how good it is!
Option Explicit
' Drive type constants
Const Unknown = 0
Const Removable = 1 ' Removable medium
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Free
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = " Unknown "
drtype(1) = " Removable "
drtype(2) = " Fixed "
drtype(3) = " Remote "
drtype(4) = " CDROM "
drtype(5) = " RAMDisk "
Text = "Drives" & vbCrLf & vbCrLf 'drives then space space
' Create FileSystemObject object to access the file system.
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter & vbTab ' Drive letter
Text = Text & drtype(curDrive.DriveType) &vbTab &vbTab
Select Case curDrive.DriveType ' Identify drive type.
Case Removable ' Removable medium
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive
End If
Case CDROM ' CD-ROM
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive ' Local drive
End If
Case Remote
Text = Text & curDrive.ShareName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive ' Network drive
Case Else ' Other medium
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.Freespace/1024, 0) & " KB" & vbCrLf' Local drive ' Local drive
End Select
Text = Text & vbCrLf
Next
MsgBox Text & Free
Any help will be greatly appreciated. This is the code that i have come up with so far. (not sure how good it is!
Option Explicit
' Drive type constants
Const Unknown = 0
Const Removable = 1 ' Removable medium
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Free
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = " Unknown "
drtype(1) = " Removable "
drtype(2) = " Fixed "
drtype(3) = " Remote "
drtype(4) = " CDROM "
drtype(5) = " RAMDisk "
Text = "Drives" & vbCrLf & vbCrLf 'drives then space space
' Create FileSystemObject object to access the file system.
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter & vbTab ' Drive letter
Text = Text & drtype(curDrive.DriveType) &vbTab &vbTab
Select Case curDrive.DriveType ' Identify drive type.
Case Removable ' Removable medium
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive
End If
Case CDROM ' CD-ROM
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive ' Local drive
End If
Case Remote
Text = Text & curDrive.ShareName & "Free: " & FormatNumber(oDrive.FreeSpace/1024, 0) & " KB" & vbCrLf' Local drive ' Network drive
Case Else ' Other medium
Text = Text & curDrive.VolumeName & "Free: " & FormatNumber(oDrive.Freespace/1024, 0) & " KB" & vbCrLf' Local drive ' Local drive
End Select
Text = Text & vbCrLf
Next
MsgBox Text & Free