citrix3 Published Application WMI

jason gilbertson Is there a way to retrieve WFApplicationName as a user through WMI? I want to run certain portions of a vbscript based on the published application the user is coming into the server with. thanks
jason
jason_a_gilbertson@homedepot.com

Rob Seiwert None that I found thru WMI but you can use the MFCOM. This is available after you install the MFSDK. I wrote something which just returns the current user session and I am sure application is available thru the same object.

Here is my code.

function usersession()
Dim theFarm, aSession, SessionState, buf

SessionState = Array(”Unknown”, _
“Active”, _
“Connected”, _
“Connecting”, _
“Shadowing”, _
“Disconnected”, _
“Idle”, _
“Listening”, _
“Resetting”, _
“Down”, _
“Init”)


‘ Create MetaFrameFarm object

Set theFarm = CreateObject(”MetaFrameCOM.MetaFrameFarm”)
if Err.Number %26lt;%26gt; 0 Then
buf = “Can’t create MetaFrameFarm object” %26#38; vbcrlf
buf = buf %26#38; “(” %26#38; Err.Number %26#38; “) ” %26#38; Err.Description
usersession=buf
exit function
End if


‘ Initialize the farm object.

theFarm.Initialize(1)

if Err.Number %26lt;%26gt; 0 Then
buf = “Can’t Initialize MetaFrameFarm object” %26#38; vbcrlf
buf = buf %26#38; “(” %26#38; Err.Number %26#38; “) ” %26#38; Err.Description
usersession=buf
exit function
End if


‘ Are you Citrix Administrator?

if theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
buf = “You must be a Citrix admin to run this script” %26#38; vbcrlf
usersession=buf
exit function
End If


‘ Print out the farm name.

buf = “MetaFrame Farm Name: ” %26#38; theFarm.FarmName %26#38; vbcrlf %26#38; vbcrlf


‘ Display all sessions in the farm.

buf = buf %26#38; “All sessions in the farm (” %26#38; Now %26#38; “)” %26#38; vbcrlf
buf = buf %26#38; “————————————————” %26#38; vbcrlf
buf = buf %26#38; padit(”Server”,10) %26#38; _
padit(”SessionName”,13) %26#38; _
padit(”ID”,5) %26#38; _
padit(”User”,15) %26#38; _
padit(”State”,15) %26#38; _
padit(”Idle”,15) %26#38; vbcrlf

For Each aSession In theFarm.Sessions

if Err.Number %26lt;%26gt; 0 Then
buf = “Can’t enumerate sessions” %26#38; vbcrlf
buf = buf %26#38; “(” %26#38; Err.Number %26#38; “) ” %26#38; Err.Description
usersession=buf
exit function
End if

buf = buf %26#38; padit(aSession.ServerName,10)
buf = buf %26#38; padit(aSession.SessionName,13)
buf = buf %26#38; padit(CStr(aSession.SessionID),5)
buf = buf %26#38; padit(aSession.UserName,15)
buf = buf %26#38; padit(SessionState(aSession.SessionState),15)
set ct=asession.currenttime(true)
set dt=aSession.Disconnecttime(true)
if asession.sessionstate=5 then
disbuf=lz(dt.month) %26#38; “/” %26#38; lz(dt.day) %26#38; ” ” %26#38; lz(dt.hour) %26#38; “:” %26#38; lz(dt.minute)
buf = buf %26#38; disbuf
end if
buf = buf %26#38; vbcrlf

Next
usersession=buf

end function


Martin Maierhofer Jason,

WMI exposes this information, here’s part of the WMI schema:

[
Association,
Dynamic: ToInstance,
Provider("MetaFrameProv"): ToInstance,
Description("Sessions have a primary app but can also enumerate all apps within a session")
]
class MetaFrame_AppsInSession
{
[key, read : ToSubClass ToInstance]
MetaFrame_Session ref Antecedent = NULL;
[key, read : ToSubClass ToInstance]
MetaFrame_Application ref Dependent = NULL;
};

So you could enumerate all applications for a given session, using this class. However, just like with MFCOM, you need to be a Citrix administrator to query information, so the script would have to be run as a Citrix administrator (rather than in a login script).

martin


Christopher King PLEASE, one teensy, tiny snippet of code…I have searched and read all of Citrix admin guides for WMI but..

I assume if the WMI Provider is running, I should be able to ‘consume’ it using a WMI Script or at the WMIC (command line) but my problem is that nowhere can I find that first two lines. I need an Alias or in a script, I would have this:

Set objWMIService = GetObject(”winmgmts:\\” %26#38; strComputer %26#38; “\root\cimv2″)

So, in that case I need the WMI path. Maybe I am just stupid but all of this oblique references is making me dizzy. Please, can someone give me that first step without jumping onto step 3? Sorry to be a pain and this is really Citrix’s well-known inability to supply quite enough documentation when it comes to scripting or providers/etc.

We don’t all use MOM!

Thanks so much in advance-ck


Martin Maierhofer Here’s a little snippet (in JScript, but that’s easily translated into VBScript — in fact the enumeration should be more natural using VBScript):

CITRIX_WMI_CONNECT = “WINMGMTS:”
+ “{impersonationLevel=impersonate,”
+ “authenticationLevel=pktPrivacy}”
+ “\\\\.\\root\\Citrix”;

var objWMIService = GetObject(CITRIX_WMI_CONNECT);
var objZonesWMICollection = objWMIService.InstancesOf(”Citrix_Zone”);
var objZoneEnum = new Enumerator(objZonesWMICollection);

for(; !objZoneEnum.atEnd(); objZoneEnum.moveNext())
{
var objWMIZone = objZoneEnum.item();
var strZoneName = objWMIZone.ZoneName;
var iNumServers = objWMIZone.NumServersInZone;

// … etc
}

Hope this helps a bit.
martin


Alessandro Torrisi Martin,

could you help me how I use the MetaFrame_AppsInSession?

the following code won’t work.

strComputer = “.”
Set objWMIService = GetObject(”winmgmts:\\” %26#38; strComputer %26#38; “\root\citrix”)
Set colItems = objWMIService.ExecQuery (”Select * from MetaFrame_AppsInSession”)

For each session in colitems
wscript.echo Session.MetaFrame_Application %26#38; ” -%26gt; ” %26#38; session.MetaFrame_Session
Next

I want to know the name of the currect published application I have started. If I know this I can use this in my login script.

Basicly I want to know when I start a published applucation, of this application is a real application, or if this is a published desktop.

Alessandro


Frank Grippi Hi Alessandro,

See code below. This is a little rough and needs some tidy up, but it should be enough to get you going. Keep in mind what was said about needing admin rights.

Hope it helpes.

-Frank

Option Explicit

Dim WshShell
Dim objWMIService, objWMICollection, objSessionApp
Dim strComputer, sSessionID, sPublishedApp

strComputer = “.”
sPublishedApp = “Citrix Desktop” ‘This is the name of the published app you are looking for

‘Connect to Namespace
Set objWMIService = GetObject(”winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}\\” %26#38; strComputer %26#38; “\root\Citrix”)

‘Get the users session ID
Set WshShell = CreateObject(”WScript.Shell”)
sSessionID = WshShell.ExpandEnvironmentStrings(”%SessionName%”)
sSessionID = Replace(sSessionID, “ICA-Tcp#”, “”)
sSessionID = “SessionID=”"” %26#38; sSessionID %26#38; “”"”
Wscript.Echo “Looking for ” %26#38; sSessionID

‘Open Class
Set objWMICollection = objWMIService.InstancesOf(”Metaframe_AppsInSession”)

‘Go through session list
For Each objSessionApp In objWMICollection
‘first find the users current session
If Instr(objSessionApp.Antecedent, sSessionID) %26gt; 0 Then
Wscript.Echo “Found User”
‘check to see if the published app we are looking for is running
If Instr(objSessionApp.Dependent, sPublishedApp) %26gt; 0 Then Wscript.Echo “Found App”
End if
Next

Category: citrix3