Advertisement
Guest User

Untitled

a guest
Jan 10th, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. OPTION EXPLICIT
  2.  
  3. CONST strComputer = "."
  4. CONST strReport = "C:\MY_WEB_DIR\freeDiskSpace.html"
  5.  
  6.  
  7. DIM objWMIService, objItem, colItems
  8. DIM strDriveType, strDiskSize, txt
  9.  
  10. SET objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
  11. SET colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
  12. 'txt = Date & vbcrlf & "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
  13. txt = "<html><body><table border=1>"
  14. 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>"
  15. FOR EACH objItem in colItems
  16.  
  17. 'ignore drives besides C:
  18. if (InStr(objItem.Name, "C:") > 0) then
  19. DIM pctFreeSpace,strFreeSpace,strusedSpace
  20.  
  21. pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
  22. strDiskSize = Int(objItem.Size /1073741824)
  23. strFreeSpace = Int(objItem.FreeSpace /1073741824)
  24. strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824)
  25. txt = txt & "<tr><td>" & Now & "</td><td>" & objItem.Name & "</td><td>" & strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & strFreeSpace & "</td><td>" & pctFreeSpace & "</td><td>"
  26. ' check for 1GB of free space
  27. if (Int(strFreeSpace) >= 1) then
  28. txt = txt & "Space is fine (>1GB) </td>"
  29. else
  30. txt = txt & "Space TOO LOW! (<1GB) </td>"
  31. end if
  32.  
  33. end if
  34. NEXT
  35.  
  36.  
  37.  
  38.  
  39. txt = txt & "</table></body></html>"
  40.  
  41. writeTextFile txt, strReport
  42. 'wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
  43.  
  44. ' Procedure to write output to a text file
  45. PRIVATE SUB writeTextFile(BYVAL txt,BYVAL strTextFilePath)
  46. DIM objFSO,objTextFile
  47.  
  48. SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
  49.  
  50. SET objTextFile = objFSO.CreateTextFile(strTextFilePath)
  51.  
  52. objTextFile.Write(txt)
  53.  
  54. objTextFile.Close
  55. SET objTextFile = NOTHING
  56. END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement