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.

79 lines
3.5 KiB

  1. '//on error resume next
  2. set objArgs = wscript.Arguments
  3. if objArgs.count < 1 then
  4. wscript.echo "Usage defrag 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. fForce = True
  17. Result = Volume.Defrag(fForce, objReport)
  18. strMessage = MapErrorCode("Win32_Volume", "Defrag", Result)
  19. wscript.echo "Volume.Defrag 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. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  57. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  58. set objMethod = objClass.methods_(strMethod)
  59. values = objMethod.qualifiers_("values")
  60. if ubound(values) < intCode then
  61. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  62. f.writeline ("FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod)
  63. MapErrorCode = ""
  64. else
  65. MapErrorCode = values(intCode)
  66. end if
  67. End Function