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.

68 lines
2.0 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. fNotDone = True
  8. strVolume = Replace(objArgs(0), "\", "\\")
  9. '// Get the volume
  10. strQuery = "select * from Win32_Volume where Name = '" & strVolume & "'"
  11. set VolumeSet = GetObject("winmgmts:").ExecQuery(strQuery)
  12. for each obj in VolumeSet
  13. set Volume = obj
  14. exit for
  15. next
  16. wscript.echo "Volume: " & Volume.Name
  17. ' illustration of how to handle input parameters - not tested
  18. Set objMethod = Volume.Methods_.Item("Format")
  19. Set objInParams = objMethod.InParameters.SpawnInstance_
  20. objInParams.ClusterSize = 4096
  21. objInParams.EnableCompression = False
  22. objInParams.FileSystem = "NTFS"
  23. objInParams.Label = ""
  24. objInParams.QuickFormat = False
  25. Set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
  26. Volume.ExecMethodAsync_ objSink, "Format", objInParams
  27. WScript.Echo "method executing..."
  28. while (fNotDone)
  29. wscript.Sleep(1000)
  30. wend
  31. Sub SINK_OnObjectReady(objObject, objAsyncContext)
  32. 'WScript.Echo objObject.Name
  33. Result = objObject.ReturnValue
  34. wscript.echo "ObjectReady: Format returned: " & Result & " : " & MapErrorCode("Win32_Volume", "Format", Result)
  35. End Sub
  36. Sub SINK_OnCompleted(intHresult, objError, objContext)
  37. WScript.Echo "OnCompleted: hresult: 0x" & Hex(intHresult)
  38. fNotDone = False
  39. End Sub
  40. Sub SINK_OnProgress(intTotal, intCurrent, strMessage, objContext)
  41. WScript.Echo "OnProgress: " & intCurrent & "/" & intTotal
  42. End Sub
  43. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  44. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  45. set objMethod = objClass.methods_(strMethod)
  46. values = objMethod.qualifiers_("values")
  47. if ubound(values) < intCode then
  48. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  49. MapErrorCode = ""
  50. else
  51. MapErrorCode = values(intCode)
  52. end if
  53. End Function