原文地址:
Win32_DiskQuota - VB Script code samples
Get instance of WMI class using GetObject
Short VBS code - get a single specified instance of Win32_DiskQuota class or get a default unnamed instance (singleton) of the class, using one single command GetObject with exact path of the wmi object.
'http://wutils.com/wmi/Dim wmiObjectSet wmiObject = GetObject( _ "WINMGMTS:\\.\ROOT\cimv2:" + _ "Win32_DiskQuota.QuotaVolume=""Path to "",User=""Path to """)Wscript.Echo wmiObject.DiskSpaceUsed 'or other property name, see table bellow
Alternative codes
SWbemServices.Get
Quickest and most efficient VB Script code to get a single instance by a key - SWbemServices.Get
'http://wutils.com/wmi/Dim oWMI, Instance'Get base WMI object, "." means computer name (local)Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")Do 'Get the instance of Win32_DiskQuota Set Instance = oWMI.Get("Win32_DiskQuota.QuotaVolume=""Path to "",User=""Path to """) 'Do something with the instance Wscript.Echo Instance.DiskSpaceUsed 'or other property name 'Wait for some time to get next value Wscript.Sleep 1000Loop While True
WMI query - sample windows WQL
Get a specified instance of Win32_DiskQuota by key, get a default unnamed instance (singleton) of the class or list instances of the class by wmi query using this VB Script.
'http://wutils.com/wmi/Dim oWMI, WQL, Instances, Instance'Get base WMI object, "." means computer name (local)Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")'Create a WMI query text WQL = "Select * from Win32_DiskQuota"'Get instances of Win32_DiskQuota Set Instances = oWMI.ExecQuery(WQL) 'Enumerate instances For Each Instance In Instances 'Do something with the instance Wscript.Echo Instance.DiskSpaceUsed 'or other property nameNext 'Instance
InstancesOf
List of all instances, wmi class Win32_DiskQuota.
'http://wutils.com/wmi/Dim oWMI, Instances, Instance'Get base WMI object, "." means computer name (local)Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")'Get instances of Win32_DiskQuota Set Instances = oWMI.InstancesOf("Win32_DiskQuota")'Enumerate instances For Each Instance In Instances 'Do something with the instance Wscript.Echo Instance.DiskSpaceUsed 'or other property nameNext 'Instance
WMI remote scripting - Locator, Connect
Get WMI management object using method. You can connect to a remote computer and specify Username/Password for the WMI connection.
'http://wutils.com/wmi/Dim Locator, oWMI, WQL, Instances, Instance'Create Locator objectSet Locator = CreateObject("WbemScripting.SWbemLocator")'Get base WMI objectSet oWMI = Locator.ConnectServer("MachineName", "ROOT\cimv2", "MachineName\administrator", "Password") '.... continue using oWMI object
Win32_DiskQuota properties
Name
CIMTypeIsArrayIsLocalOriginreadUnitswritekeyValueMapQualifiersDiskSpaceUsed
21,uint64NOYESWin32_DiskQuotaTrue"Bytes"-Limit
21,uint64NOYESWin32_DiskQuotaTrue"Bytes"True-key
QuotaVolume
102,ref:NOYESWin32_DiskQuotaTrueTrue-Status
19,uint32NOYESWin32_DiskQuotaTrueArray["0","1","2"]-key
User
102,ref:NOYESWin32_DiskQuotaTrueTrue-WarningLimit
21,uint64NOYESWin32_DiskQuotaTrue"Bytes"True-Win32_DiskQuota derivation
Win32_DiskQuota is top level class. See or .
Sample of Instances (Win 2003 Server)
Number of instances: 9999, Key Names:QuotaVolume,User
Win32_DiskQuota Qualifiers
Name
ValueToInstanceToSubclassOverridableAmendedLocalAssociation
TrueYESYESNONOYESCreateBy
"PutInstance"NONOYESNOYESDeleteBy
"DeleteInstance"NONOYESNOYESdynamic
TrueYESNOYESNOYESLocale
&1033YESNOYESNOYESprovider
"DskQuotaProvider"YESNOYESNOYESSupportsCreate
TrueNONOYESNOYESSupportsDelete
TrueNONOYESNOYESSupportsUpdate
TrueNONOYESNOYESUUID
"B94560CA-41CC-4FB5-BD56-282329DA41DA"YESNOYESNOYES
Win32_DiskQuota System properties
Name
ValueOriginCimTypeLocalArray__PATH
"\\TRIPLE\ROOT\cimv2:Win32_DiskQuota"___SYSTEM8FalseFalse__NAMESPACE
"ROOT\cimv2"___SYSTEM8FalseFalse__SERVER
"TRIPLE"___SYSTEM8FalseFalse__DERIVATION
Array[]___SYSTEM8FalseTrue__PROPERTY_COUNT
&6___SYSTEM3FalseFalse__RELPATH
"Win32_DiskQuota"___SYSTEM8FalseFalse__DYNASTY
"Win32_DiskQuota"___SYSTEM8FalseFalse__SUPERCLASS
___SYSTEM8FalseFalse__CLASS
"Win32_DiskQuota"___SYSTEM8FalseFalse__GENUS
&1___SYSTEM3FalseFalse- WMI reference for windows server. Quick VBScript and c# code samples.