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.

253 lines
8.4 KiB

  1. on error resume next
  2. set objArgs = wscript.Arguments
  3. if objArgs.count < 1 then
  4. wscript.echo "Usage badParam 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 = 0
  17. wscript.echo "ScheduleAutoChk tests -------------------------------------"
  18. Result = Volume.ScheduleAutoChk(Null)
  19. rc = ReportIfErr(Err, "FAILED - ScheduleAutoChk")
  20. strMessage = MapErrorCode("Win32_Volume", "ScheduleAutoChk", Result)
  21. if Result <> 0 then
  22. wscript.echo "Volume.ScheduleAutoChk returned: " & Result & " : " & strMessage
  23. end if
  24. Result = 0
  25. DIM aVolumes(1)
  26. aVolumes(0) = "BogusVolume1"
  27. aVolumes(1) = "BogusVolume2"
  28. Result = Volume.ScheduleAutoChk(aVolumes)
  29. rc = ReportIfErr(Err, "FAILED - ScheduleAutoChk")
  30. strMessage = MapErrorCode("Win32_Volume", "ScheduleAutoChk", Result)
  31. if Result <> 0 then
  32. wscript.echo "Volume.ScheduleAutoChk returned: " & Result & " : " & strMessage
  33. end if
  34. Result = 0
  35. aVolumes(0) = "C:\"
  36. aVolumes(1) = "BogusVolume2"
  37. Result = Volume.ScheduleAutoChk(aVolumes)
  38. rc = ReportIfErr(Err, "FAILED - ScheduleAutoChk")
  39. strMessage = MapErrorCode("Win32_Volume", "ScheduleAutoChk", Result)
  40. if Result <> 0 then
  41. wscript.echo "Volume.ScheduleAutoChk returned: " & Result & " : " & strMessage
  42. end if
  43. Result = 0
  44. wscript.echo "ExcludeFromAutoChk tests ----------------------------------"
  45. Result = Volume.ExcludeFromAutoChk(Null)
  46. rc = ReportIfErr(Err, "FAILED - ExcludeFromAutoChk")
  47. strMessage = MapErrorCode("Win32_Volume", "ExcludeFromAutoChk", Result)
  48. if Result <> 0 then
  49. wscript.echo "Volume.ExcludeFromAutoChk returned: " & Result & " : " & strMessage
  50. end if
  51. Result = 0
  52. aVolumes(0) = "BogusVolume1"
  53. aVolumes(1) = "BogusVolume2"
  54. Result = Volume.ExcludeFromAutoChk(aVolumes)
  55. rc = ReportIfErr(Err, "FAILED - ExcludeFromAutoChk")
  56. strMessage = MapErrorCode("Win32_Volume", "ExcludeFromAutoChk", Result)
  57. if Result <> 0 then
  58. wscript.echo "Volume.ExcludeFromAutoChk returned: " & Result & " : " & strMessage
  59. end if
  60. Result = 0
  61. aVolumes(0) = "C:\"
  62. aVolumes(1) = "BogusVolume2"
  63. Result = Volume.ExcludeFromAutoChk(aVolumes)
  64. rc = ReportIfErr(Err, "FAILED - ExcludeFromAutoChk")
  65. strMessage = MapErrorCode("Win32_Volume", "ExcludeFromAutoChk", Result)
  66. if Result <> 0 then
  67. wscript.echo "Volume.ExcludeFromAutoChk returned: " & Result & " : " & strMessage
  68. end if
  69. Result = 0
  70. wscript.echo "Chkdsk tests ----------------------------------------------"
  71. Result = Volume.Chkdsk(Null,Null,Null,Null,Null,Null,Null)
  72. rc = ReportIfErr(Err, "FAILED - Chkdsk")
  73. strMessage = MapErrorCode("Win32_Volume", "Chkdsk", Result)
  74. if Result <> 0 then
  75. wscript.echo "Volume.Chkdsk returned: " & Result & " : " & strMessage
  76. end if
  77. Result = 0
  78. Result = Volume.Chkdsk("this","is","not","a","boolean","type"," param")
  79. rc = ReportIfErr(Err, "FAILED - Chkdsk")
  80. strMessage = MapErrorCode("Win32_Volume", "Chkdsk", Result)
  81. if Result <> 0 then
  82. wscript.echo "Volume.Chkdsk returned: " & Result & " : " & strMessage
  83. end if
  84. Result = 0
  85. wscript.echo "AddMountPoint tests ---------------------------------------"
  86. Result = Volume.AddMountPoint(Null)
  87. rc = ReportIfErr(Err, "FAILED - AddMountPoint")
  88. strMessage = MapErrorCode("Win32_Volume", "AddMountPoint", Result)
  89. if Result <> 0 then
  90. wscript.echo "Volume.AddMountPoint returned: " & Result & " : " & strMessage
  91. end if
  92. Result = 0
  93. Result = Volume.AddMountPoint("This is a bogus directory")
  94. rc = ReportIfErr(Err, "FAILED - AddMountPoint")
  95. strMessage = MapErrorCode("Win32_Volume", "AddMountPoint", Result)
  96. if Result <> 0 then
  97. wscript.echo "Volume.AddMountPoint returned: " & Result & " : " & strMessage
  98. end if
  99. Result = 0
  100. wscript.echo "Dismount tests --------------------------------------------"
  101. Result = Volume.Dismount(Null,Null)
  102. rc = ReportIfErr(Err, "FAILED - Dismount")
  103. strMessage = MapErrorCode("Win32_Volume", "Dismount", Result)
  104. if Result <> 0 then
  105. wscript.echo "Volume.Dismount returned: " & Result & " : " & strMessage
  106. end if
  107. Result = 0
  108. Result = Volume.Dismount("bogus",-1)
  109. rc = ReportIfErr(Err, "FAILED - Dismount")
  110. strMessage = MapErrorCode("Win32_Volume", "Dismount", Result)
  111. if Result <> 0 then
  112. wscript.echo "Volume.Dismount returned: " & Result & " : " & strMessage
  113. end if
  114. Result = 0
  115. wscript.echo "Defrag tests ----------------------------------------------"
  116. Result = Volume.Defrag(Null,Null)
  117. rc = ReportIfErr(Err, "FAILED - Defrag")
  118. strMessage = MapErrorCode("Win32_Volume", "Defrag", Result)
  119. if Result <> 0 then
  120. wscript.echo "Volume.Defrag returned: " & Result & " : " & strMessage
  121. end if
  122. Result = 0
  123. Result = Volume.Defrag("non-boolean",Null)
  124. rc = ReportIfErr(Err, "FAILED - Defrag")
  125. strMessage = MapErrorCode("Win32_Volume", "Defrag", Result)
  126. if Result <> 0 then
  127. wscript.echo "Volume.Defrag returned: " & Result & " : " & strMessage
  128. end if
  129. Result = 0
  130. Result = Volume.Defrag(True,"non obj")
  131. rc = ReportIfErr(Err, "FAILED - Defrag")
  132. strMessage = MapErrorCode("Win32_Volume", "Defrag", Result)
  133. if Result <> 0 then
  134. wscript.echo "Volume.Defrag returned: " & Result & " : " & strMessage
  135. end if
  136. Result = 0
  137. wscript.echo "DefragAnalysis tests --------------------------------------"
  138. Result = Volume.DefragAnalysis(Null,Null)
  139. rc = ReportIfErr(Err, "FAILED - DefragAnalysis")
  140. strMessage = MapErrorCode("Win32_Volume", "DefragAnalysis", Result)
  141. if Result <> 0 then
  142. wscript.echo "Volume.DefragAnalysis returned: " & Result & " : " & strMessage
  143. end if
  144. Result = 0
  145. Result = Volume.DefragAnalysis(boolType,"non obj")
  146. rc = ReportIfErr(Err, "FAILED - DefragAnalysis")
  147. strMessage = MapErrorCode("Win32_Volume", "DefragAnalysis", Result)
  148. if Result <> 0 then
  149. wscript.echo "Volume.DefragAnalysis returned: " & Result & " : " & strMessage
  150. end if
  151. Result = 0
  152. wscript.echo "Format tests ----------------------------------------------"
  153. Result = Volume.Format(Null, Null, Null, Null, Null)
  154. rc = ReportIfErr(Err, "FAILED - Format")
  155. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  156. if Result <> 0 then
  157. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  158. end if
  159. Result = 0
  160. Result = Volume.Format("NTFS", "Non-boolean")
  161. rc = ReportIfErr(Err, "FAILED - Format")
  162. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  163. if Result <> 0 then
  164. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  165. end if
  166. Result = 0
  167. Result = Volume.Format("BogusFileSystem", True)
  168. rc = ReportIfErr(Err, "FAILED - Format")
  169. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  170. if Result <> 0 then
  171. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  172. end if
  173. Result = 0
  174. Result = Volume.Format("NTFS", True, 198743190374103410382)
  175. rc = ReportIfErr(Err, "FAILED - Format")
  176. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  177. if Result <> 0 then
  178. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  179. end if
  180. Result = 0
  181. Result = Volume.Format("NTFS", True, , "A Bogus Label That Is Too Long By A Wide Margin")
  182. rc = ReportIfErr(Err, "FAILED - Format")
  183. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  184. if Result <> 0 then
  185. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  186. end if
  187. Result = 0
  188. Result = Volume.Format("NTFS", True, , , "non-boolean-type")
  189. rc = ReportIfErr(Err, "FAILED - Format")
  190. strMessage = MapErrorCode("Win32_Volume", "Format", Result)
  191. if Result <> 0 then
  192. wscript.echo "Volume.Format returned: " & Result & " : " & strMessage
  193. end if
  194. Result = 0
  195. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  196. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  197. set objMethod = objClass.methods_(strMethod)
  198. values = objMethod.qualifiers_("values")
  199. if ubound(values) < intCode then
  200. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  201. MapErrorCode = ""
  202. else
  203. MapErrorCode = values(intCode)
  204. end if
  205. End Function
  206. Function ReportIfErr(ByRef objErr, ByRef strMessage)
  207. ReportIfErr = objErr.Number
  208. if objErr.Number <> 0 then
  209. strError = strMessage & " : " & Hex(objErr.Number) & " : " & objErr.Description
  210. wscript.echo (strError)
  211. objErr.Clear
  212. end if
  213. End Function