We help IT Professionals succeed at work.

citrix logoff script pass back to local pc

does anyone know of a way to run a shutdown sequence on the local pc when logging off a citrix xenapp full desktop session? i.e. so if a user logs off citrix full published desktop it will shutdown the windows 7 pc they are locally using.
Comment
Watch Question

You can try this thread

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27591958.html

you will have to modify script to shutdown i.e.

"shutdown -s -t 00 -f"

this shutdown your PC.
Ayman BakrSenior Consultant
CERTIFIED EXPERT

Commented:
Check the following similar thread (instead of logging off you will have to modify the script to shut down):

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27591958.html
you can also add reason & comments for your shutdown.

shutdown -s -t 120 -d P:00:00 -c "Citrix Session Log off and Guest PC Shutdown Script"
Mutawadi: Thread already been posted.Please read/refresh before posting.

Author

Commented:
issue i have is i dont think mine is the same as using a login script that runs the followign to launch a full desktop straight off.
"C:\Program Files\Citrix\ICA Client\pnagent.exe" /CitrixShortcut: (1) /QLaunch "xenapp:Full Desktop"

is there a way a could modify yours to work with this
Tony JohncockLead Technical Architect
CERTIFIED EXPERT

Commented:
You could also create a powershell script (you mentioned Windows 7 in the tags) to monitor the process and invoke an action when it ends.

start-sleep -seconds 15
$Process="PNAgent"
 $proc = Get-Process | Where-Object {$_.ProcessName -eq $Process}
 while ($true)
 {
 while (!($process))
 {
 $proc = Get-Process | Where-Object {$_.ProcessName -eq $Process}
 start-sleep -seconds 5
 }
 if ($proc)
 {
 $proc.WaitForExit()
 start-sleep -seconds 5
 $proc = Get-Process | Where-Object {$_.ProcessName -eq $Process}
$wsh = New-Object -ComObject wscript.shell
write-host "Shutting down local PC in 10 seconds"
$Shutdown = "shutdown.exe -s -t 10"
$wsh.run $shutdown
}
 }

Save it as a .PS1 file (you will have to invoke powershell executionpolicy to run all) and invoke it in a login script on the local PC

i.e. create a simple batch file that contains:

c:\windows\system32\windowspowershell\v1.0\powershell.exe -executionpolicy unrestricted scriptname.ps1

Assuming you called the above scriptname.ps1

There is a 15 second delay at the start to ensure the PNAgent process has time to start (you could put it in the same login script just to be sure) and the script pauses for 5s per loop.
You could use the system variable called clientname to shut the local computer down from the Citrix servers logoff script.

shutdown \\%clientname% /t:120 "Computer is shutting down" /y /c

//Kent
Tony JohncockLead Technical Architect
CERTIFIED EXPERT

Commented:
Yeah but that won't work if there's a CAG/WI server as it gets obfuscated.

Author

Commented:
yes it has a webinterface
If it is a must to let the Web Interface change the names, and it is done for some reason - Citrix policies for example - then I agree, but you could configure web interface to not changing the client names, if that would fit your existing demands.

//Kent.
Tony JohncockLead Technical Architect
CERTIFIED EXPERT

Commented:
And preventing WI from changing the name has a nasty side effect in that it tends to break other things such as session reconnect and workspace control.
Senior Citrix Engineer
CERTIFIED EXPERT
Commented:
Montoring this from the client side is by far the easiest way to do this.  It is similar to what Tony1044 has posted above.

option explicit
dim bFirstResults, bLaterResults, wshShell
dim oWMI, colProcesses

bFirstResults = vbTrue
bLaterResults = vbFalse

Do Until bFirstResults = vbTrue
wscript.sleep(10000)
bFirstResults = FirstPass()
Loop

Do
wscript.sleep(10000)
bLaterResults = LaterPass()
Loop Until bLaterResults = vbFalse

set wshShell = CreateObject ("wscript.shell")
wshShell.Run "shutdown.exe /s /t 5", 0, vbFalse

Function FirstPass()
set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
set colProcesses = oWMI.ExecQuery  ("SELECT * FROM Win32_Process WHERE Name = wfica32.exe")
if colProcesses.Count = 0 then
bFirstResults = vbFalse
else
bFirstResults = vbTrue
end if
FirstPass = bFirstResults
end function

Function LaterPass()
set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
set colProcesses = oWMI.ExecQuery  ("SELECT * FROM Win32_Process WHERE Name = wfica32.exe")
if colProcesses.Count = 0 then
bLaterResults = vbFalse
else
bLaterResults = vbTrue
end if
LaterPass = bFirstResults
end function

Open in new window


This isn't completely tested yet.  You basically assign this as a login script for the user on the client side device.  It checks to see if wfica32.exe is running (which is the runtime for a live connection).  It keeps checking until it sees it (first pass).

Then, once it has seen it, it starts the LaterPass watching for the exe.  When it doesn't find it, it shuts the system down.  The only caveat is LaterPass is running on a 10 second pass, but the sleep cycle can be adjusted.

Coralon
Tony JohncockLead Technical Architect
CERTIFIED EXPERT

Commented:
And Coralon's script has the added advantage of being in VBScript which means it'll run natively on Windows XP.