2

I'm using WMI to do some Citrix work, specifically to search for a particular user to log off. First I have to enumerate an object called MetaFrame_Session, which lists current sessions, then from that I have to retrieve an object called Citrix_User, which has the user name.

The Session object contains a reference to the User object, but I am not very familiar with WMI and I'm stumped as to how to get the actual object from the reference. Examples of how to do this in VBScript would be very helpful

Lizz
  • 1,442
  • 5
  • 25
  • 51
Graham Powell
  • 283
  • 1
  • 12

2 Answers2

0

Seems you couldn't find an answer on this other forum, either, but the code to log off a Citrix session using WMI was kindly posted here as follows by Haydn Davies for one Citrix server:

' Logoff Disconnected Sessions
' If you want to logoff active sessions as well, change the query to include
' cActive
On Error Resume Next

Const cActive = 0
Const cDisconnected = 4
Const strComputer = "."

Set objWMICitrix = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\citrix")
Set colItems = objWMICitrix.ExecQuery ("Select * from Metaframe_Session Where sessionstate = " & cDisconnected)

For Each objItem in colItems
if (objItem.SessionID > 0) and (objItem.SessionID < 65530) then
objItem.Logoff
end if
Next

Set objWMICitrix = Nothing

See here for code on how to get a Citrix VirtualIP, since it might help as reference for techniques. Also, if you find the WMI is broken on the server, see here for repairing.

Lizz
  • 1,442
  • 5
  • 25
  • 51
  • can you answer my question here if that issue has been resolved: http://stackoverflow.com/questions/18092577/how-to-get-wmi-object-from-a-wmi-object-reference – Saher Ahwal Aug 07 '13 at 00:11
  • @Saher sorry, I don't think I can answer what you're looking for. :( – Lizz Aug 07 '13 at 04:29
0

you can do that with string manipulation, because "SessionUser" is a string

dim name
For Each objItem in colItems
name=left(Mid(objItem.SessionUser,InStr(objItem.SessionUser,"=")+2,20),InStr(Mid(objItem.SessionUser,InStr(objItem.SessionUser,"=")+2,20),",")-2)
 if (name="YOUR_SEARCH_NAME") and (objItem.SessionID < 65530) then
objItem.Logoff
end if
Marcin
  • 1