-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPerformAction.ps1
60 lines (53 loc) · 1.86 KB
/
PerformAction.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Make a published app with the command line executable:
#ctxhide C:\Path\PerformAction.ps1
#Application to initially open by user: path to exe and processname as found by get-process
$launch = "C:\windows\system32\notepad.exe"
$procname = "notepad"
#$arglist = "Arg1 Arg2 Arg3"
#process to run on disconnected state
$myproc = "c:\Program Files (x86)\Internet Explorer\iexplore.exe"
#open app
Start-Process $launch #-ArgumentList $arglist
#get the SessionID - first list the correct session ID
start-sleep 10
function Get-TSSessions {
param(
$ComputerName = "localhost"
)
qwinsta /server:$ComputerName |
#Parse output
ForEach-Object {
$_.Trim() -replace "\s+",","
} |
#Convert to objects
ConvertFrom-Csv
}
#set session variable to correct sessionID, and then start exe running loop
$session = (Get-TSSessions |? {$_.USERNAME -eq "$env:username"}|? {$_.TYPE -eq "wdica"}).ID
Add-PSSnapin Citrix.XenApp.Commands -ErrorAction Stop
#Check to see if $appname is running. Remove write-host to see state of script
while ((get-process -name $procname|Where-Object {$_.SessionID -eq $session}) -ne $null)
{
#If active sleep script
while (((Get-XASession -ServerName $env:computername|?{$_.AccountName -match $env:username}|?{$_.Protocol -match "ica"}).state -eq "Active") -and ((get-process -name $procname|Where-Object {$_.SessionID -eq $session}) -ne $null))
#discheck = 1 means it hasnt been secured
{
#Write-host "sleeping"
$discheck = "1"
start-sleep -m 500
}
#if disconnected do this stuff
if ($discheck -eq "1"){
#Write-host "run action"
#############################
start-process $myproc
#uncomment below to run a vbscript
#run a vbscript::::::cscript "C:\TEMP\MYFILE.vbs"
$discheck = "0"
}
else{
start-sleep -m 500
#Write-host "Disconnected - process ran"
}
}
#write-host "no exe running"