Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OPTION EXPLICIT
- CONST strComputer = "."
- CONST strReport = "C:\MY_WEB_DIR\freeDiskSpace.html"
- DIM objWMIService, objItem, colItems
- DIM strDriveType, strDiskSize, txt
- SET objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
- SET colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
- 'txt = Date & vbcrlf & "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
- txt = "<html><body><table border=1>"
- txt = txt & "<tr><td>Date</td><td>Drive</td><td>Size (GB)</td><td>Used (GB)</td><td>Free (GB)</td><td>Free (%)</td><td>Status</td></tr>"
- FOR EACH objItem in colItems
- 'ignore drives besides C:
- if (InStr(objItem.Name, "C:") > 0) then
- DIM pctFreeSpace,strFreeSpace,strusedSpace
- pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
- strDiskSize = Int(objItem.Size /1073741824)
- strFreeSpace = Int(objItem.FreeSpace /1073741824)
- strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824)
- txt = txt & "<tr><td>" & Now & "</td><td>" & objItem.Name & "</td><td>" & strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & strFreeSpace & "</td><td>" & pctFreeSpace & "</td><td>"
- ' check for 1GB of free space
- if (Int(strFreeSpace) >= 1) then
- txt = txt & "Space is fine (>1GB) </td>"
- else
- txt = txt & "Space TOO LOW! (<1GB) </td>"
- end if
- end if
- NEXT
- txt = txt & "</table></body></html>"
- writeTextFile txt, strReport
- 'wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
- ' Procedure to write output to a text file
- PRIVATE SUB writeTextFile(BYVAL txt,BYVAL strTextFilePath)
- DIM objFSO,objTextFile
- SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
- SET objTextFile = objFSO.CreateTextFile(strTextFilePath)
- objTextFile.Write(txt)
- objTextFile.Close
- SET objTextFile = NOTHING
- END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement