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.

288 lines
8.7 KiB

  1. 'tempAccount = "Win32_Account.Domain=""NTDEV"",Name=""harshita"""
  2. dim strNamespace
  3. dim tempAccount
  4. dim objAdmin
  5. dim strUsage
  6. strUsage = "usage: Quotas.vbs <host|.> <drivePath>"
  7. if (wscript.Arguments.Count <> 2) then
  8. wscript.echo ("wrong number of arguments")
  9. wscript.echo (strUsage)
  10. wscript.quit
  11. end if
  12. strNamespace = "winmgmts://" & wscript.Arguments(0) & "/root/cimv2"
  13. strVolume = wscript.Arguments(1)
  14. strVolume = Replace (strVolume, "\", "\\")
  15. set objNSVolumeUserQuota = GetObject(strNamespace & ":Win32_VolumeUserQuota").SpawnInstance_
  16. sysAccountName = "NETWORK SERVICE"
  17. logFileName = "log_Quotas.txt"
  18. Set fso = CreateObject("Scripting.FileSystemObject")
  19. result = fso.FileExists(logFileName)
  20. if (result = true) then
  21. fso.DeleteFile(logFileName)
  22. end if
  23. set f = fso.CreateTextFile(logFileName)
  24. strQuery = "select * from Win32_Volume where Name = '" & strVolume & "'"
  25. set VolumeSet = GetObject(strNamespace).ExecQuery(strQuery)
  26. rc = ReportIfErr(Err, " FAILED - volume query operation failed")
  27. for each obj in VolumeSet
  28. set Volume = obj
  29. exit for
  30. next
  31. if IsNull(Volume.DriveLetter) then
  32. wscript.echo ("specified volume must have a drive letter assigned")
  33. wscript.echo (strUsage)
  34. wscript.quit
  35. end if
  36. strQuery1 = "select * from Win32_LogicalDisk where Name = '" & volume.driveletter & "'"
  37. set DiskSet = GetObject(strNamespace).ExecQuery(strQuery1)
  38. rc = ReportIfErr(Err, " FAILED - logicaldisk query operation failed")
  39. for each diskobj in DiskSet
  40. set disk = diskobj
  41. exit for
  42. next
  43. call VUQTests ()
  44. call ClassComparisons()
  45. call DisplaySummary()
  46. '********************************************************************************
  47. function VUQTests ()
  48. on error resume next
  49. Set objSystemAccount = GetObject(strNamespace).ExecQuery _
  50. ("Select * from Win32_SystemAccount where name ='NETWORK SERVICE'")
  51. rc = ReportIfErr(Err, " FAILED - SystemAccount query operation failed")
  52. for each objSysAccount in objSystemAccount
  53. strAccountRef = objSysAccount.Path_.RelPath
  54. exit for
  55. next
  56. strVolumeRef = volume.Path_.RelPath
  57. objNSVolumeUserQuota.Volume = strVolumeRef
  58. objNSVolumeUserQuota.Account = strAccountRef
  59. objNSVolumeUserQuota.Limit = 10000
  60. objNSVolumeUserQuota.WarningLimit = 500
  61. objNSVolumeUserQuota.DiskSpaceUsed = 0
  62. objNSVolumeUserQuota.Status = 0
  63. wscript.echo ("attempting creation of VolumeUserQuota")
  64. objNSVolumeUserQuota.Put_
  65. rc = ReportIfErr(Err, " FAILED - VolumeUserQuota Put operation failed")
  66. wscript.echo ("checking creation of new VolumeUserQuota")
  67. tempAccount = strAccountRef 'used in tests later
  68. set myAssoc = volume.Associators_("Win32_VolumeUserQuota")
  69. rc = ReportIfErr(Err, "FAILED - volume associators query operation failed")
  70. found = FALSE
  71. for each account in myAssoc
  72. if (account.name = sysAccountName) then
  73. found = TRUE
  74. call WriteLog (" success - new VolumeUserQuota created")
  75. end if
  76. next
  77. if (found = FALSE) then
  78. call WriteLog (" FAILURE - new VolumeUserQuota creation")
  79. call WriteLog (" SKIPPING - updation and deletion of VolumeUserQuota")
  80. end if
  81. objNSVolumeUserQuota.Refresh_
  82. rc = ReportIfErr(Err, " FAILED - VolumeUserQuota Refresh operation failed")
  83. wscript.echo ("")
  84. wscript.echo ("Attempting updation of VolumeUserQuota")
  85. wscript.echo (" objNSVolumeUserQuota.WarningLimit = "&objNSVolumeUserQuota.WarningLimit)
  86. wscript.echo (" objNSVolumeUserQuota.Limit = "&objNSVolumeUserQuota.Limit)
  87. wscript.echo (" setting WarningLimit = Limit")
  88. objNSVolumeUserQuota.WarningLimit = objNSVolumeUserQuota.Limit
  89. objNSVolumeUserQuota.Put_
  90. rc = ReportIfErr(Err, " FAILED - VolumeUserQuota Put operation failed")
  91. wscript.echo (" doing a refresh")
  92. objNSVolumeUserQuota.Refresh_
  93. rc = ReportIfErr(Err, " FAILED - VolumeUserQuota Refresh operation failed")
  94. wscript.echo (" validating updation")
  95. if (objNSVolumeUserQuota.WarningLimit = objNSVolumeUserQuota.Limit) then
  96. call WriteLog (" success - updation of VolumeUserQuota")
  97. else
  98. call WriteLog (" FAILURE - updation of VolumeUserQuota")
  99. end if
  100. wscript.echo ("")
  101. wscript.echo ("deleting above VolumeUserQuota")
  102. objNSVolumeUserQuota.Delete_
  103. rc = ReportIfErr(Err, " FAILED - VolumeUserQuota Delete operation failed")
  104. set myAssoc = volume.Associators_("Win32_VolumeUserQuota")
  105. found = FALSE
  106. for each account in myAssoc
  107. if (account.name = sysAccountName) then
  108. found = TRUE
  109. call WriteLog (" FAILED - new VolumeUserQuota deletion")
  110. end if
  111. next
  112. if (found = FALSE) then
  113. call WriteLog (" success - new VolumeUserQuota deletion")
  114. end if
  115. end function
  116. '********************************************************************************
  117. function DisplaySummary()
  118. f.Close
  119. Set f = fso.OpenTextFile(logFileName)
  120. wscript.echo ("")
  121. wscript.echo ("***************************************")
  122. wscript.echo (" Test Summary ")
  123. wscript.echo ("***************************************")
  124. wscript.echo ("")
  125. Do While f.AtEndOfStream <> True
  126. wscript.echo(f.ReadLine)
  127. Loop
  128. wscript.echo ("")
  129. wscript.echo ("***************************************")
  130. wscript.echo (" End of Test Summary ")
  131. wscript.echo ("***************************************")
  132. wscript.echo ("")
  133. f.Close
  134. end function
  135. '********************************************************************************
  136. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode, ByRef strMessage)
  137. set objClass = GetObject(strNamespace).Get(strClass, &h20000)
  138. set objMethod = objClass.methods_(strMethod)
  139. values = objMethod.qualifiers_("values")
  140. if ubound(values) < intCode then
  141. call WriteLog(" FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod)
  142. strMessage = ""
  143. else
  144. strMessage = values(intCode)
  145. end if
  146. End Function
  147. '********************************************************************************
  148. function classComparisons()
  149. wscript.echo ("")
  150. wscript.echo ("VolumeQuota Association Classes:")
  151. set volumeReferences = volume.References_("Win32_VolumeQuota")
  152. set diskReferences = disk.References_("Win32_VolumeQuotaSetting")
  153. for each myThing in volumeReferences
  154. Wscript.Echo " Element: "&myThing.Element
  155. Wscript.Echo " Setting: "&myThing.Setting
  156. next
  157. wscript.echo ("")
  158. wscript.echo ("VolumeQuotaSetting Association Classes:")
  159. for each myThing in diskReferences
  160. Wscript.Echo " Element: "&myThing.Element
  161. Wscript.Echo " Setting: "&myThing.Setting
  162. next
  163. wscript.echo ("")
  164. wscript.echo ("VolumeUserQuota Association Classes:")
  165. set myReferences = volume.References_("Win32_VolumeUserQuota")
  166. set diskReferences = disk.References_("Win32_DiskQuota")
  167. For each myThing in myReferences
  168. wscript.echo ""
  169. Wscript.Echo " Volume: "& vbTab & myThing.Volume
  170. Wscript.Echo " Account: "&myThing.Account
  171. Wscript.Echo " Status: "&myThing.Status
  172. Wscript.Echo " Limit: "&myThing.Limit
  173. Wscript.Echo " Warning Limit: "&myThing.WarningLimit
  174. Wscript.Echo " DiskSpaceUsed: "&myThing.DiskSpaceUsed
  175. Next
  176. wscript.echo ("")
  177. wscript.echo ("DiskQuota Association Classes:")
  178. For each myThing in diskReferences
  179. wscript.echo ""
  180. Wscript.Echo " QuotaVolume: "& vbTab & myThing.QuotaVolume
  181. wscript.echo " User: "& myThing.User
  182. Wscript.Echo " Status: "&myThing.Status
  183. Wscript.Echo " Limit: "&myThing.Limit
  184. Wscript.Echo " Warning Limit: "&myThing.WarningLimit
  185. Wscript.Echo " DiskSpaceUsed: "&myThing.DiskSpaceUsed
  186. Next
  187. wscript.echo ("")
  188. call WriteLog (" success - all associator classes retrieved")
  189. end function
  190. '********************************************************************************
  191. function DisplayVUQ (byref obj)
  192. wscript.echo ""
  193. Wscript.Echo " Volume: "& vbTab & obj.Volume
  194. Wscript.Echo " Account: "&obj.Account
  195. Wscript.Echo " Status: "&obj.Status
  196. Wscript.Echo " Limit: "&obj.Limit
  197. Wscript.Echo " Warning Limit: "&obj.WarningLimit
  198. Wscript.Echo " DiskSpaceUsed: "&obj.DiskSpaceUsed
  199. end function
  200. '********************************************************************************
  201. Function ReportIfErr(ByRef objErr, ByRef strMessage)
  202. ReportIfErr = objErr.Number
  203. if objErr.Number <> 0 then
  204. strError = strMessage & " : " & Hex(objErr.Number) & " : " & objErr.Description
  205. call WriteLog (strError)
  206. objErr.Clear
  207. end if
  208. End Function
  209. Sub WriteLog(ByRef strMessage)
  210. wscript.echo strMessage
  211. f.writeline strMessage
  212. End Sub