WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: oldone1 on November 26, 2013, 02:29:14 AM

Title: Using Winbatch to query WMI association classes
Post by: oldone1 on November 26, 2013, 02:29:14 AM
This is just a generic question. There is a WMI association class named Win32_GroupUser.  It is an association of The Win32_Group class and the Win32_User class.  It has only 2 properties.  These are the key fields for each of the base classes.  I can reference these properties in the normal manner

  data1 = obj.partcomponent (Partcomponent is the key field for the USER class).

My question is is it possible to reference the other fields of the  base classes thru the association class.  If possible, how is it accomplished?
Title: Re: Using Winbatch to query WMI association classes
Post by: Deana on November 26, 2013, 10:48:05 AM
Yes I believe you can access the properties of the associated class.  The Win32_GroupUser association WMI class relates a group and an account that is a member of that group. You can use the results to get an instance of the associated class.

UNDEBUGGED

Code (winbatch) Select
ComputerName = "."
objwmiServices  = ObjectGet ( "winmgmts:{impersonationLevel=Impersonate}!//" : ComputerName)
objects =  objwmiServices.ExecQuery ( "SELECT * FROM Win32_GroupUser")
ForEach objRoot In objects
    If ObjectTypeGet(objRoot)=="EMPTY" then continue
    partComponent = objRoot.PartComponent
    Pause("Account", partComponent )
    groupComponent =  objRoot.groupComponent
    Pause("Group", groupComponent )
   
    objUserAcct  = ObjectGet( 'winmgmts:{impersonationLevel=impersonate}!': partComponent )
    type = ObjectTypeGet(objUserAcct)
    If type =="EMPTY" then continue
    data_user = "Name: " : objUserAcct.Name : @lf
    data_user = data_user : "AccountType: " : objUserAcct.AccountType : @lf
    data_user = data_user : "Domain: " : objUserAcct.Domain : @lf
    data_user = data_user : "FullName: " : objUserAcct.FullName : @lf
    data_user = data_user : "SID: " : objUserAcct.SID
    Pause("Win32_UserAccount", data_user )

    objGroup  = ObjectGet( 'winmgmts:{impersonationLevel=impersonate}!': groupComponent )
    type = ObjectTypeGet(objGroup)
    If type =="EMPTY" then continue
    data_group = "Name: " : objGroup.Name
    Pause("Win32_Group", data_group )   
Next
exit

Title: Re: Using Winbatch to query WMI association classes
Post by: oldone1 on November 27, 2013, 10:47:02 AM
Thank you for information.  With a few adjustments, the process worked.  Actually, the associated group that I gave you was one that I had worked with before.  In that case I just used the groupcomponent and partcomponent fields and manipulated them.  This was due to the fact that these fields contained the data that I wanted.  The real associated class that I wished to process was  CIM_VideoSetting.  This would allow me to duplicate the obtaining of current resolutions available.  It works with one minor flaw.  The result has colors instead of pixel depth.

I have one question regarding your script.  You used the actual property name in your assignment statement 
  partComponent = objRoot.PartComponent

and then the same name in the ObjectGet

statement

objUserAcct  = ObjectGet( 'winmgmts:{impersonationLevel=impersonate}!': partComponent )

Is that a requirement or just your standard method ?

Once again, thanks for the response.
Title: Re: Using Winbatch to query WMI association classes
Post by: td on November 27, 2013, 01:17:20 PM
If you are referring to the actual name of the variable that receives the property value, it can be any valid WIL variable name.  However, it is generally accepted standard programming or scripting practice to use meaningful identifiers for variable names.