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.

185 lines
6.2 KiB

  1. Option Explicit
  2. '//on error resume next
  3. Dim objArgs
  4. Dim objVolume, objSet, obj
  5. Dim strQuery, strVolume, strHost, strNamespace
  6. set objArgs = wscript.Arguments
  7. if objArgs.count < 2 then
  8. wscript.echo "Usage rwprop <host> <volumePath>"
  9. wscript.quit(1)
  10. end if
  11. strHost = objArgs(0)
  12. strVolume = Replace(objArgs(1), "\", "\\")
  13. strNamespace = "winmgmts://" & strHost & "/root/cimv2"
  14. '// Get the volume
  15. strQuery = "select * from Win32_Volume where Name = '" & strVolume & "'"
  16. set objSet = GetObject(strNamespace).ExecQuery(strQuery)
  17. for each obj in objSet
  18. set objVolume = obj
  19. exit for
  20. next
  21. wscript.echo "Volume: " & objVolume.Name
  22. wscript.echo "----------------------------------------------"
  23. wscript.echo "--DriveLetter tests"
  24. wscript.echo "----------------------------------------------"
  25. Call DriveLetter(objVolume)
  26. wscript.echo "----------------------------------------------"
  27. wscript.echo "--Label tests"
  28. wscript.echo "----------------------------------------------"
  29. Call Label(objVolume)
  30. wscript.echo "----------------------------------------------"
  31. wscript.echo "--IndexingEnabled tests"
  32. wscript.echo "----------------------------------------------"
  33. Call IndexingEnabled(objVolume)
  34. sub DriveLetter(ByRef objVolume)
  35. 'on error resume next
  36. Dim rc
  37. Dim strOrigDriveLetter
  38. strOrigDriveLetter = objVolume.DriveLetter
  39. wscript.echo "DriveLetter= " & objVolume.DriveLetter
  40. if IsNull(objVolume.DriveLetter) then
  41. call SetVerifyProperty(objVolume, "DriveLetter", "M:")
  42. else
  43. call SetVerifyProperty(objVolume, "DriveLetter", Null)
  44. end if
  45. call SetVerifyProperty(objVolume, "DriveLetter", "N:")
  46. call SetVerifyProperty(objVolume, "DriveLetter", "P:")
  47. call SetVerifyProperty(objVolume, "DriveLetter", Null)
  48. wscript.echo "EXPECT FAILURE - assigning SuperBogusDriveLetter string"
  49. call SetVerifyProperty(objVolume, "DriveLetter", "SuperBogusDriveLetter")
  50. wscript.echo "EXPECT FAILURE - assigning -1"
  51. call SetVerifyProperty(objVolume, "DriveLetter", -1)
  52. call SetVerifyProperty(objVolume, "DriveLetter", strOrigDriveLetter)
  53. end sub
  54. sub Label(ByRef objVolume)
  55. on error resume next
  56. Dim rc, strOrigLabel
  57. strOrigLabel = objVolume.Label
  58. wscript.echo "Label= " & objVolume.Label
  59. if IsNull(objVolume.Label) then
  60. call SetVerifyProperty(objVolume, "Label", "superbad")
  61. else
  62. call SetVerifyProperty(objVolume, "Label", Null)
  63. end if
  64. call SetVerifyProperty(objVolume, "Label", "sexmachine")
  65. call SetVerifyProperty(objVolume, "Label", "getonup")
  66. call SetVerifyProperty(objVolume, "Label", "")
  67. call SetVerifyProperty(objVolume, "Label", Null)
  68. wscript.echo "EXPECT FAILURE - assigning SuperLongBogusLabelString..."
  69. call SetVerifyProperty(objVolume, "Label", "SuperLongBogusLabelStringThatShouldBeWayTooLongForSuccess")
  70. wscript.echo "EXPECT FAILURE - assigning -1"
  71. call SetVerifyProperty(objVolume, "Label", -1)
  72. call SetVerifyProperty(objVolume, "Label", strOrigLabel)
  73. end sub
  74. sub IndexingEnabled(ByRef objVolume)
  75. on error resume next
  76. Dim rc, fIndex
  77. fIndex = objVolume.IndexingEnabled
  78. if fIndex = True then
  79. call SetVerifyProperty(objVolume, "IndexingEnabled", False)
  80. else
  81. call SetVerifyProperty(objVolume, "IndexingEnabled", True)
  82. end if
  83. call SetVerifyProperty(objVolume, "IndexingEnabled", False)
  84. call SetVerifyProperty(objVolume, "IndexingEnabled", 0)
  85. call SetVerifyProperty(objVolume, "IndexingEnabled", True)
  86. call SetVerifyProperty(objVolume, "IndexingEnabled", 1)
  87. wscript.echo "EXPECT FAILURE - assigning perLongBogusLabelString..."
  88. call SetVerifyProperty(objVolume, "IndexingEnabled", "SuperLongBogusLabelStringThatShouldBeWayTooLongForSuccess")
  89. wscript.echo "EXPECT FAILURE - assigning -102331"
  90. call SetVerifyProperty(objVolume, "IndexingEnabled", -102331)
  91. call SetVerifyProperty(objVolume, "IndexingEnabled", fIndex)
  92. end sub
  93. sub SetVerifyProperty(ByRef objInOut, ByRef strProp, ByRef Value)
  94. on error resume next
  95. dim objPropSet, objProp, RefreshValue, rc
  96. set objPropSet = objInOut.Properties_
  97. set objProp = objPropSet.Item(strProp)
  98. wscript.echo "setting " & objInOut.Path_.Class & "." & strProp & "=" & Value
  99. objProp.Value = Value
  100. objInOut.Put_
  101. rc = ReportIfErr(Err, "FAILED - " & objInOut.Path_.Class & " put operation")
  102. set objInOut = RefreshObject(objInOut)
  103. rc = ReportIfErr(Err, "FAILED - " & objInOut.Path_.Class & " refresh operation")
  104. set objPropSet = objInOut.Properties_
  105. set objProp = objPropSet.Item(strProp)
  106. RefreshValue = objProp.Value
  107. wscript.echo "refreshed " & objInOut.Path_.Class & "." & strProp & "=" & RefreshValue
  108. end sub
  109. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  110. Dim objClass, objMethod
  111. Dim values
  112. set objClass = GetObject(strNamespace).Get(strClass, &h20000)
  113. set objMethod = objClass.methods_(strMethod)
  114. values = objMethod.qualifiers_("values")
  115. if ubound(values) < intCode then
  116. wscript.echo " FAILED - no error message found for " & intCode & " : " & strClass & "." & strMethod
  117. MapErrorCode = ""
  118. else
  119. MapErrorCode = values(intCode)
  120. end if
  121. End Function
  122. Function ReportIfErr(ByRef objErr, ByRef strMessage)
  123. Dim strError
  124. ReportIfErr = objErr.Number
  125. if objErr.Number <> 0 then
  126. strError = strMessage & " : " & Hex(objErr.Number) & " : " & objErr.Description
  127. wscript.echo (strError)
  128. objErr.Clear
  129. Set objLastError = CreateObject("wbemscripting.swbemlasterror")
  130. wscript.wcho("Provider: " & objLastError.ProviderName)
  131. wscript.wcho("Operation: " & objLastError.Operation)
  132. wscript.wcho("Description: " & objLastError.Description)
  133. wscript.wcho("StatusCode: 0x" & Hex(objLastError.StatusCode))
  134. end if
  135. End Function
  136. Function RefreshObject(ByRef objIn)
  137. on error resume next
  138. Dim strRelPath, rc
  139. set RefreshObject = GetObject(strNamespace).Get(objIn.Path_)
  140. rc = ReportIfErr(Err, "FAILED - " & objIn.Path_.Class & ".Get operation")
  141. End Function