Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.7 KiB

  1. '//on error resume next
  2. set objArgs = wscript.Arguments
  3. if objArgs.count < 1 then
  4. wscript.echo "Usage defragAnalysis volume"
  5. wscript.quit(1)
  6. end if
  7. strVolume = Replace(objArgs(0), "\", "\\")
  8. '// Get the volume
  9. strQuery = "select * from Win32_Volume where Name = '" & strVolume & "'"
  10. set VolumeSet = GetObject("winmgmts:").ExecQuery(strQuery)
  11. for each obj in VolumeSet
  12. set Volume = obj
  13. exit for
  14. next
  15. wscript.echo "Volume: " & Volume.Name
  16. Result = Volume.DefragAnalysis(fRecommended, objReport)
  17. wscript.echo "result " & result
  18. strMessage = MapErrorCode("Win32_Volume", "DefragAnalysis", Result)
  19. wscript.echo "Volume.DefragAnalysis returned: " & Result & " : " & strMessage
  20. if Result = 0 then
  21. wscript.echo "Analysis Report"
  22. wscript.echo ""
  23. wscript.echo " Volume size = " & objReport.VolumeSize
  24. wscript.echo " Cluster size = " & objReport.ClusterSize
  25. wscript.echo " Used space = " & objReport.UsedSpace
  26. wscript.echo " Free space = " & objReport.FreeSpace
  27. wscript.echo " Percent free space = " & objReport.FreeSpacePercent
  28. wscript.echo ""
  29. wscript.echo "Volume fragmentation"
  30. wscript.echo " Total fragmentation = " & objReport.TotalPercentFragmentation
  31. wscript.echo " File fragmentation = " & objReport.FilePercentFragmentation
  32. wscript.echo " Free space fragmentation = " & objReport.FreeSpacePercentFragmentation
  33. wscript.echo ""
  34. wscript.echo "File fragmentation"
  35. wscript.echo " Total files = " & objReport.TotalFiles
  36. wscript.echo " Average file size = " & objReport.AverageFileSize
  37. wscript.echo " Total fragmented files = " & objReport.TotalFragmentedFiles
  38. wscript.echo " Total excess fragments = " & objReport.TotalExcessFragments
  39. wscript.echo " Average fragments per file = " & objReport.AverageFragmentsPerFile
  40. wscript.echo ""
  41. wscript.echo "Pagefile fragmentation"
  42. wscript.echo " Pagefile size = " & objReport.PagefileSize
  43. wscript.echo " Total fragments = " & objReport.TotalPagefileFragments
  44. wscript.echo ""
  45. wscript.echo "Folder fragmentation"
  46. wscript.echo " Total folders = " & objReport.TotalFolders
  47. wscript.echo " Fragmented folders = " & objReport.FragmentedFolders
  48. wscript.echo " Excess folder fragments = " & objReport.ExcessFolderFragments
  49. wscript.echo ""
  50. wscript.echo "Master File Table (MFT) fragmentation"
  51. wscript.echo " Total MFT size = " & objReport.TotalMFTSize
  52. wscript.echo " MFT record count = " & objReport.MFTRecordCount
  53. wscript.echo " Percent MFT in use = " & objReport.MFTPercentInUse
  54. wscript.echo " Total MFT fragments = " & objReport.TotalMFTFragments
  55. wscript.echo ""
  56. if fRecommended = True then
  57. wscript.echo "this volume should be defragged"
  58. else
  59. wscript.echo "this volume does not need to be defragged"
  60. end if
  61. end if
  62. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  63. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  64. set objMethod = objClass.methods_(strMethod)
  65. values = objMethod.qualifiers_("values")
  66. if ubound(values) < intCode then
  67. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  68. f.writeline ("FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod)
  69. MapErrorCode = ""
  70. else
  71. MapErrorCode = values(intCode)
  72. end if
  73. End Function