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.

103 lines
3.3 KiB

  1. '//on error resume next
  2. set objArgs = wscript.Arguments
  3. if objArgs.count < 1 then
  4. PrintUsage()
  5. wscript.quit(1)
  6. end if
  7. if objArgs.count = 1 then
  8. if objArgs(0) = "/?" then
  9. PrintUsage()
  10. wscript.quit
  11. end if
  12. end if
  13. strVolume = Replace(objArgs(0), "\", "\\")
  14. DIM fFixErrors
  15. DIM fRecoverBadSectors
  16. DIM fForceDismount
  17. DIM fVigorousIndex
  18. DIM fSkipFolderCycle
  19. DIM fOkToRunAtBootup
  20. fFixErrors = False
  21. fRecoverBadSectors = False
  22. fForceDismount = False
  23. fVigorousIndex= True
  24. fSkipFolderCycle= False
  25. fOkToRunAtBootup= False
  26. DIM i, j
  27. for i = 0 to objArgs.count-1
  28. if (LCase(objArgs(i)) = "/f") then
  29. fFixErrors = True
  30. end if
  31. if (LCase(objArgs(i)) = "/r") then
  32. fRecoverBadSectors = True
  33. end if
  34. if (LCase(objArgs(i)) = "/x") then
  35. fForceDismount = True
  36. end if
  37. if (LCase(objArgs(i)) = "/i") then
  38. fVigorousIndex= False
  39. end if
  40. if (LCase(objArgs(i)) = "/c") then
  41. fSkipFolderCycle= True
  42. end if
  43. if (LCase(objArgs(i)) = "/b") then
  44. fOkToRunAtBootup= True
  45. end if
  46. next
  47. '// Get the volume
  48. strQuery = "select * from Win32_Volume where Name = '" & strVolume & "'"
  49. set VolumeSet = GetObject("winmgmts:").ExecQuery(strQuery)
  50. for each obj in VolumeSet
  51. set Volume = obj
  52. exit for
  53. next
  54. wscript.echo "Volume: " & Volume.Name
  55. Result = Volume.Chkdsk(fFixErrors, fVigorousIndex, fSkipFolderCycle, fForceDismount, fRecoverBadSectors, fOkToRunAtBootup)
  56. strMessage = MapErrorCode("Win32_Volume", "Chkdsk", Result)
  57. wscript.echo "Volume.Chkdsk returned: " & Result & " : " & strMessage
  58. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  59. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  60. set objMethod = objClass.methods_(strMethod)
  61. values = objMethod.qualifiers_("values")
  62. if ubound(values) < intCode then
  63. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  64. f.writeline ("FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod)
  65. MapErrorCode = ""
  66. else
  67. MapErrorCode = values(intCode)
  68. end if
  69. End Function
  70. Function PrintUsage()
  71. wscript.echo "chkdsk volumePath /f /r /i /c /x /b"
  72. wscript.echo ""
  73. wscript.echo "volumePath Specifies the drive path, mount point, or volume name."
  74. wscript.echo " /f Fixes errors on the disk."
  75. wscript.echo " /r Locates bad sectors and recovers readable information"
  76. wscript.echo " (implies /F)."
  77. wscript.echo " /x Forces the volume to dismount first if necessary."
  78. wscript.echo " All opened handles to the volume would then be invalid"
  79. wscript.echo " (implies /F)."
  80. wscript.echo " /i NTFS only: Performs a less vigorous check of index entries."
  81. wscript.echo " /c NTFS only: Skips checking of cycles within the folder"
  82. wscript.echo " structure."
  83. wscript.echo " /b Schedules chkdsk operation on reboot if volume is locked"
  84. wscript.echo ""
  85. wscript.echo "The /i or /c switch reduces the amount of time required to run Chkdsk by"
  86. wscript.echo "skipping certain checks of the volume."
  87. End Function