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.

75 lines
2.2 KiB

  1. '//on error resume next
  2. set objArgs = wscript.Arguments
  3. if objArgs.count < 1 then
  4. wscript.echo "Usage format 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. ' illustration of how to handle input parameters - not tested
  17. Set objMethod = Volume.Methods_.Item("Format")
  18. Set objInParams = objMethod.InParameters.SpawnInstance_
  19. objInParams.ClusterSize = 4096
  20. objInParams.EnableCompression = False
  21. objInParams.FileSystem = "NTFS"
  22. objInParams.Label = ""
  23. objInParams.QuickFormat = False
  24. fNotCancel = True
  25. Set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
  26. Volume.ExecMethodAsync_ objSink, "Format", objInParams
  27. WScript.Echo "method executing..."
  28. while (fNotCancel)
  29. wscript.Sleep(1000)
  30. wend
  31. objSink.cancel
  32. Sub SINK_OnObjectReady(objObject, objAsyncContext)
  33. 'WScript.Echo objObject.Name
  34. Result = objObject.ReturnValue
  35. wscript.echo "ObjectReady: Format returned: " & Result & " : " & MapErrorCode("Win32_Volume", "Format", Result)
  36. End Sub
  37. Sub SINK_OnCompleted(intHresult, objError, objContext)
  38. WScript.Echo "OnCompleted: hresult: 0x" & Hex(intHresult)
  39. fNotDone = False
  40. End Sub
  41. Sub SINK_OnProgress(intTotal, intCurrent, strMessage, objContext)
  42. WScript.Echo "OnProgress: " & intCurrent & "/" & intTotal
  43. if intCurrent > 25 AND fNotCancel = True then
  44. wscript.echo "OnProgress: progress above 25% cancelling call..."
  45. fNotCancel = False
  46. end if
  47. End Sub
  48. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  49. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  50. set objMethod = objClass.methods_(strMethod)
  51. values = objMethod.qualifiers_("values")
  52. if ubound(values) < intCode then
  53. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  54. MapErrorCode = ""
  55. else
  56. MapErrorCode = values(intCode)
  57. end if
  58. End Function