Using Winbatch to query WMI association classes

Started by oldone1, November 26, 2013, 02:29:14 AM

Previous topic - Next topic

oldone1

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?

Deana

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

Deana F.
Technical Support
Wilson WindowWare Inc.

oldone1

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.

td

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.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade