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!

Help needed with script

Status
Not open for further replies.

BobSakemano

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

Could you have a look at tis script


Dim objFSO, objDrives, objDrive
Dim nFreeSpace, nTotalSize, nSpaceUsed, nPercentUsed

Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objDrives = objFSO.Drives

For Each objDrive In objDrives

If objDrive.DriveType = 2 And objDrive.DriveLetter = C Then

nFreeSpace = objDrive.AvailableSpace / 1048576
nTotalSize = objDrive.TotalSize / 1048576
nSpaceUsed = nTotalSize - nFreeSpace

If (nSpaceUsed/nTotalSize > 0.90 ) Then

WScript.echo


End If

End If
Next

It doesnt work but maybe you guys can see what I'm doing wrong?
 
Hi Bob,

maybe you can use the function I used in one of my scripts.
It generates a comma seperated output for that specific machine for all found drives...

Code:
Function CheckServerDiskSpace (ByVal strServerName)
	Dim objWMIService, objDisks, objDisk
	Dim strDiskID, strFreeSpace, strTotalSize, strFreeSpacePercent
	Dim strServerInfo
	Dim iTemp
	Const HARD_DISK = 3
	
	on error resume Next
	Err.number = 0
	Set objWMIService = GetObject("winmgmts:\\" & strServerName & "\root\cimv2")
	if err.number<>0 then
		WScript.echo = strServerName & "=Error:;" & err.number & " - " & err.description
		exit function
	end If
	On Error goto 0
	strServerInfo = strServerName
	Set objDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " & HARD_DISK & "")
	For Each objDisk in objDisks
		strDiskID = objDisk.DeviceID
		strTotalSize = objDisk.Size / 1073741824		'in GigaBytes
			iTemp = InStr (strTotalSize,".")
			If iTemp = 0 Then iTemp = InStr (strTotalSize,",")
			strTotalSize = Left (strTotalSize,(iTemp + 4))
		strFreeSpace = objDisk.FreeSpace / 1073741824	'in Gigabytes
			iTemp = InStr (strFreeSpace,".")
			If iTemp = 0 Then iTemp = InStr (strFreeSpace,",")
			strFreeSpace = Left (strFreeSpace,(iTemp + 4))
		strFreeSpacePercent = (strFreeSpace / strTotalSize) * 100	'in Percent
			iTemp = InStr (strFreeSpacePercent,".")
			If iTemp = 0 Then iTemp = InStr (strFreeSpacePercent,",")
			strFreeSpacePercent = Left (strFreeSpacePercent,(iTemp + 2))
		strServerInfo = strServerInfo & "=" & strDiskID & ";" & strTotalSize & " Gb;" & _
						strFreeSpace & " Gb;" & strFreeSpacePercent
	Next
	CheckServerDiskSpace = strServerInfo
End Function

Good luck...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
>If objDrive.DriveType = 2 And objDrive.DriveLetter = C Then
If objDrive.DriveType = 2 And objDrive.DriveLetter = [red]"[/red]C[red]"[/red] Then
 
Typical example of the usefulness of Option Explicit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top