BigDaddyO Posted April 7, 2020 Posted April 7, 2020 I've got a bunch of test accounts that go into Citrix and occasionally my test goes off the rails and strands a few dozen/hundred Citrix sessions active but not working. I need to log them off manually in order for me to run my test again since it relies on login scripts to kick off my test. I've got this script that tells me which users are currently logged into the citrix box that I've connected to, but I can't figure out how to log those test accounts off. I've tried to RunAs shutdown /l /f but it just logs me off instead. Anybody have some Ideas? Thanks #include <AutoItConstants.au3> $sDomain = "domain" $sTestAccounts = 'loadUSER' ;My test accounts all start the same $sPassword = "TheP@ssw0rd" ;All test accounts have the same password ;Identify every user that is logged into this Citrix server $iPID = Run(@ComSpec & ' /C QUERY USER', "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput & @CRLF) $aLoggedOn = StringSplit($sOutput, @LF) ConsoleWrite($aLoggedOn[0] & " Accounts logged into this box, now to see which are my test accounts" & @CRLF) ;Identify the test accounts we are looking for Global $aTestAccounts[$aLoggedOn[0]] ;This will store those test accounts we find logged into this system $a = 0 For $i = 1 to $aLoggedOn[0] $sRow = StringStripWS($aLoggedOn[$i], 3) If StringLeft($sRow, StringLen($sTestAccounts)) = $sTestAccounts Then $a += 1 $aTestAccounts[$a] = StringLeft($sRow, StringInStr($sRow, " ") - 1) EndIf Next ;Move through the test accounts and log them off "Somehow" For $d = 1 to $a ConsoleWrite("This user needs to be logged off '" & $aTestAccounts[$d] & "'" & @CRLF) ;Tried 0, 1, 2, 4 and it just logs me off instead! ;~ RunAs($sUserName, $sDomain, $sPassword, 4, @SystemDir & "\shutdown.exe /l /f", "", @SW_SHOW) ;~ Exit Next
FrancescoDiMuro Posted April 8, 2020 Posted April 8, 2020 @BigDaddyO Untested, but this seems a valid solution (Method 2) BigDaddyO 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
BigDaddyO Posted April 8, 2020 Author Posted April 8, 2020 Thanks @FrancescoDiMuro I don't have the ability to do the elevated cmd as I'm not an admin, but I was able to use my existing Query User which gives me the Session Name and ID. then combine the RunAs using the Logoff SessionName. #include <AutoItConstants.au3> $sTestAccounts = 'testUSER' ;My test accounts all start the same $sPassword = "Th3P@ssw0rd" ;All test accounts have the same password ;Identify every user that is logged into this Citrix server $iPID = Run(@ComSpec & ' /C QUERY USER', "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput & @CRLF) $aLoggedOn = StringSplit($sOutput, @LF) ConsoleWrite($aLoggedOn[0] & " Accounts logged into this box, now to see which are my test accounts" & @CRLF) ;Identify the test accounts we are looking for and their sessionname For $i = 1 to $aLoggedOn[0] $sRow = StringStripWS($aLoggedOn[$i], 3) If StringLeft($sRow, StringLen($sTestAccounts)) = $sTestAccounts Then $sTabDel = StringRegExpReplace($sRow, "\s+", @TAB) $aCol = StringSplit($sTabDel, @TAB) If $aCol[0] < 2 Then ContinueLoop ConsoleWrite("Log off this test user '" & StringStripWS($aCol[1], 3) & "' on Session Name '" & StringStripWS($aCol[2], 3) & "'" & @CRLF) RunAs(StringStripWS($aCol[1], 3), @LogonDomain, $sPassword, 4, "logoff " & StringStripWS($aCol[2], 3), "", @SW_SHOW) EndIf Next
Subz Posted April 8, 2020 Posted April 8, 2020 Do you have access to Director? We usually give our helpdesk staff access, to shadow, log off sessions etc..
BigDaddyO Posted April 8, 2020 Author Posted April 8, 2020 nope, I already asked for the Helpdesk type access just for this test env and was denied (very political here, All access is granted only by job role) which is why I had to do it this way. if you know citrix, perhaps you will know of LoginVSI. I built my own version of that using AutoIt and a MS SQL database. working great so far but lots of moving pieces. I've now got 24 launcher servers able to handle 600 citrix sessions.
Subz Posted April 8, 2020 Posted April 8, 2020 We generally only use Citrix for staff without laptops to connect in remotely from home, however majority of staff have laptops and VPN access. Although since the lock down we've had to extend our Citrix licensing and add additional host servers to handle the extra load during business hours, that's $50k we'll probably never fully utilize (probably would have been cheaper to just buy the staff laptops). I've never used LoginVSI but looks like an interesting tool, although once we come out of lock down, I expect usage to drop again, so would probably be overkill in our environment, I mean prior to lockdown we'd be lucky to have 50 staff connecting concurrently. Just glad it's not my money FrancescoDiMuro 1
BigDaddyO Posted April 8, 2020 Author Posted April 8, 2020 in my co, majority of people use citrix and there are a few apps that are only available from inside citrix which are the apps that I need to run my tests against. with the whole lock down thing we are sitting at about 20,000 simultaneous citrix sessions. Only IT and management have laptops.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now