MSSC_support
asked on
Force windows log off when Citrix ICA client closes
Hi All,
We have pass through authentication cofigured on our environment to PCs on our computers configured as dumb terminals via group policy restrictions. When the user logs off their Citrix session, they have to log off Windows again to log off the PC. Is there a way to have the windows log off wrapped with the log off request on citrix?
Possibly a simple batch file or vbs wrapper script. I am struggling with this and cannot get it to work.
Trying the batch file to launch the ica client does not work for me and therefore I cannot run the shutdown /l command.
The above only launches another cmd
Can any one help?
We have pass through authentication cofigured on our environment to PCs on our computers configured as dumb terminals via group policy restrictions. When the user logs off their Citrix session, they have to log off Windows again to log off the PC. Is there a way to have the windows log off wrapped with the log off request on citrix?
Possibly a simple batch file or vbs wrapper script. I am struggling with this and cannot get it to work.
Trying the batch file to launch the ica client does not work for me and therefore I cannot run the shutdown /l command.
start /wait //"location of ica client"/icafile.ica
shutdown /l
The above only launches another cmd
Can any one help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Line 36 has a problem when I run the script.
ASKER
dim objShell
set objShell = WScript.CreateObject("WScr ipt.Shell" )
objShell.Run(%windir% & "\System32\Logoff.exe")
Set objShell = Nothing
This whole bit does not run... I am no scripting expert so I cannot see what is wrong here.
set objShell = WScript.CreateObject("WScr
objShell.Run(%windir% & "\System32\Logoff.exe")
Set objShell = Nothing
This whole bit does not run... I am no scripting expert so I cannot see what is wrong here.
ASKER
I ran it with the whole directory path instead and it seems to log off now :)
Apologies - I didn't test the logoff section as I didn't want to be logged off... Glad to hear you got it working though! ;-)
Very coarse description:
Lines 1-5 create some variables to hold the values we want to use
Lines 7-11 populate the variables with values
Lines 14-18 ask the system to notify it of processes that are terminating
Lines 21-24 start the ICA client with the profile you specify
Lines 27-30 wait for a notification and then check to see if the process that terminated was the ICA client
Line 32 isn't needed - I was using it to confirm that the loop condition was met
Lines 34-37 trigger the logoff
Quick note: line 37 should probably be: objShell.Run("%windir%\Sys tem32\Logo ff.exe")
Very coarse description:
Lines 1-5 create some variables to hold the values we want to use
Lines 7-11 populate the variables with values
Lines 14-18 ask the system to notify it of processes that are terminating
Lines 21-24 start the ICA client with the profile you specify
Lines 27-30 wait for a notification and then check to see if the process that terminated was the ICA client
Line 32 isn't needed - I was using it to confirm that the loop condition was met
Lines 34-37 trigger the logoff
Quick note: line 37 should probably be: objShell.Run("%windir%\Sys
ASKER
Tried your above line 37 and it still does not work. However, now my other problem is that when I run it it cannot find the file specified for line 9 to run line 23 even though it is all in the right place. Any ideas?
ASKER
Oops found out it was the (x86) part in Program Files (X86).. But when the VBS runs... it terminates and logs off before Citrix starts! Almost there
ASKER
I will try to put a WSscript Sleep to wait for the ICA to actually start and then will give you an update.
ASKER
Nope still does not work. I think it just does not see the ICA client and therefore just bring up ICA Client Terminated echo box with OK.
ASKER
Also, I have changed the logoff obshell.run for log off to "shutdown /l /t 001 /f", 1, TRUE so that it forces the log off rather than it wait for the user to press ok.
If you manually run the ICA client what process(es) does it start? I don't actually use ICA so I am guessing at the process involved based on a quick install I did of the Citrix Connection Manager and an empty .ica file...
PS: while testing it you might want to replace the logoff with calc.exe or some other innocuous executable otherwise you'll spend half your time logging in/out!
PS: while testing it you might want to replace the logoff with calc.exe or some other innocuous executable otherwise you'll spend half your time logging in/out!
ASKER
When I run it manually i get wifca32.exe and wfcrun32.exe
I am already experiencing the pain of logging in and out! i will change to calc.
I am already experiencing the pain of logging in and out! i will change to calc.
How're you launching the script? It is a shortcut on the desktop? The Startup folder in the menu? A GPO logon script?
ASKER
At the moment I am just launching it by double clicking it to test from a shared folder on the client pc.
Unless the application handles an invalid .ica file differently than a valid config file I am at a bit of a loss. The following script works for me every time I run it:
As you've already found you'd need to strip out the ' (x86)' from the strExecutablePath and update strICAProfilePath with the real path of your .ica but appart from that I am not sure what the difference would be. I'll have to think on it.
In the meantime maybe an actual Expert will chip in... :)
dim strExecutablePath
dim strExecutableName
dim strICAProfilePath
dim strLatestProcessName
dim strComputer
strExecutablePath = "C:\Program Files (x86)\Citrix\ICA Client\"
strExecutableName = "wfcrun32.exe"
strICAProfilePath = "C:\Users\%username%\Downloads\test.ica"
strLatestProcessName = ""
strComputer = "."
'Opt to receive notifications about processes that terminate
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancedeletionevent " _
& "within 1 where TargetInstance isa 'Win32_Process'")
'Start the ICA Client
dim objShell
set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run(Chr(34) & strExecutablePath & strExecutableName & Chr(34) & " " & Chr(34) & strICAProfilePath & Chr(34))
'Listen for the termination of the ICA Client executable
Do Until strLatestProcessName = strExecutableName
Set objLatestProcess = colMonitoredProcesses.NextEvent
strLatestProcessName = objLatestProcess.TargetInstance.Name
Loop
objShell.Run("%windir%\System32\calc.exe")
Set objShell = Nothing
As you've already found you'd need to strip out the ' (x86)' from the strExecutablePath and update strICAProfilePath with the real path of your .ica but appart from that I am not sure what the difference would be. I'll have to think on it.
In the meantime maybe an actual Expert will chip in... :)
ASKER
Well it all launches ok... but as soon as I run the script it tries to do the log off part of the script whilst Citrix is loading/running. It is as if it cannot see the Citrix Process. I am not sure what could be stopping the script from seeing this. Also, we are using Xenapp 6 and the CitrixOnlinePluginWeb.msi version of the client. I have not tried it with Citrix Receiver but in any case the process it looks for in your script is the last opened process.
It occurs to me that I'm testing on a Windows 7 machine... Can I just check - what OS is your client running? I am guessing Windows XP s it is one of the tags for this thread...
ASKER
it is XP
ASKER
I have managed to get it working by looking for the wfcrun32.exe process specifically and then forcing windows to log off once it has terminated. Thank you very much for your help.
ASKER
Got me on track and I managed to write my own script.
ASKER