WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System_Management
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WMI Query

 Keywords: System.Management System.Management.EnumerationOptions System.Management.ManagementObjectSearcher Get WMI Class Get Query .Net dotNet  

;***************************************************************************
;**   Query WMI
;**
;** Purpose: Query WMI
;** Inputs:
;**       strScope
;**       strQry
;** Outputs:
;** Revisions:
;** Reference:
;**       REQUIRES WinBatch 2013A or newer
;**       
;** Developer: Deana Falk 2013.05.02
;***************************************************************************
If Version( )< '2013A'
   Pause("Notice", "Need 2013A or Newer Version of WInBatch")
   Exit
EndIf

strScope = "root\cimv2"
strQry = "SELECT * FROM Win32_Service"

bTrue = ObjectType( "BOOL", 1 )
bFalse = ObjectType( "BOOL", 0 )

ObjectClrOption( "use", "System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" )
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Set enumerations options
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oEnum = ObjectClrNew( "System.Management.EnumerationOptions" )
;oEnum.BlockSize = 1                ; block size for block operations. When enumerating through a collection, WMI will return results in groups of the specified size.  
;oEnum.Context =                    ; sets a WMI context object. This is a name-value pairs list to be passed through to a WMI provider that supports context information for customized operation.  (Inherited from ManagementOptions.) 
oEnum.DirectRead = bFalse           ; direct access to the WMI provider is requested for the specified class, without any regard to its super class or derived classes.  
oEnum.EnsureLocatable = bFalse      ; objects returned should have locatable information in them. This ensures that the system properties, such as __PATH, __RELPATH, and __SERVER, are non-NULL. This flag can only be used in queries, and is ignored in enumerations.  
oEnum.EnumerateDeep = bFalse        ; recursive enumeration is requested into all classes derived from the specified superclass. If false, only immediate derived class members are returned.  
oEnum.PrototypeOnly = bFalse        ; query should return a prototype of the result set instead of the actual results. This flag is used for prototyping.  
oEnum.ReturnImmediately = bTrue     ; RECOMMENDED TRUE: the invoked operation should be performed in a synchronous or semisynchronous fashion. If this property is set to true, the enumeration is invoked and the call returns immediately. The actual retrieval of the results will occur when the resulting collection is walked.  
oEnum.Rewindable = bFalse           ; RECOMMENDED FALSE: the collection is assumed to be rewindable. If true, the objects in the collection will be kept available for multiple enumerations. If false, the collection can only be enumerated one time.  
;oEnum.Timeout =                    ; time-out to apply to the operation. Note that for operations that return collections, this time-out applies to the enumeration through the resulting collection, not the operation itself (the ReturnImmediately property is used for the latter). This property is used to indicate that the operation should be performed semi-synchronously.  (Inherited from ManagementOptions.) 
oEnum.UseAmendedQualifiers = bFalse ; the objects returned from WMI should contain amended information. Typically, amended information is localizable information attached to the WMI object, such as object and property descriptions.  
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

oManagementObjectSearcher = ObjectClrNew( "System.Management.ManagementObjectSearcher", strScope, strQry, oEnum )
cManagementObjectCol = oManagementObjectSearcher.Get()

Data = ''
ForEach object In cManagementObjectCol
   ret = object.ToString()
   If Data == "" then Data = object.ToString()
   Else Data = Data : @lf : object.ToString()
Next
Pause( 'WMI Query', Data )
exit


Article ID:   W17821
Filename:   WMI Query.txt
File Created: 2013:05:02:12:10:42
Last Updated: 2013:05:02:12:10:42