Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simplest way to get Disk Freespace in VBS

Status
Not open for further replies.

BobSakemano

Technical User
Feb 17, 2005
20
0
0
NL
hey guys,

whats the easiest and most simple way to get the disk freespace of a certian partition in VBS?

I'm now using WMI but thats too much code for something this simple, I thought maybe there is a better way.

thanks
 
Take a look at the AvailableSpace property of the Drive object exposed by FileSystemObject.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Here is what I use.

Code:
strComputer = "."
Dim strDiskInfo
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisk = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk In colDisk
	IF objDisk.Size <> 0 Then
		strDiskInfo = "Drive Letter: " & objDisk.Caption & Chr(10) & _
			"Size: " & Round(objDisk.Size/1073741824,2) & Chr(10) & _
			"Free Space: " & Round(objDisk.FreeSpace/1073741824,2) & Chr(10) & _
			"% Free: " & FormatPercent(objDisk.FreeSpace/objDisk.Size,2) & Chr(10)
	Else
		strDiskInfo = "Drive Letter: " & objDisk.Caption & Chr(10) & _
		"Disk Not Present"
	End If
	WScript.Echo strDiskInfo
Next

I know you said you didn't want to use WMI, but if it ain't broke, why fix it?
 
I had a look around the web and like PHV said, AvailableSpace of de fsobject is the easiest! thanks guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top