Jump to content

Alternate to qwinsta.exe to identify Active RDP Citrix Session


Recommended Posts

I have a bunch of scripts that I need to run on systems that are either accessed from RDP or Citrix.

The problem I have had all along is that if you close the RDP or Citrix screen then the scripts will fail even if the user is still logged into the system you were connected to.

I finally found something that will tell me if the session is still active but it's a command line tool called qwinsta.exe.  I prefer not to do stdoutread if there is any other way so I'm wondering if anyone has an idea on how to get the session state for the currently logged in user as this script does but not using stdoutread?

$RunFrom = EnvGet("Sessionname")
ConsoleWrite("Active SessionName = " & $RunFrom & @CRLF & @CRLF)

Local $iPID = Run('"C:\Windows\System32\qwinsta.exe" ' & @UserName, "", @SW_HIDE, 2)
ProcessWaitClose($iPID)                                             ;Need to wait for it to finish before we get the StdOutput values

$sOutput = StdoutRead($iPID)                                        ;Retrieve whatever returned
ConsoleWrite("Active StdOutRead = " & @CRLF & $sOutput & @CRLF & @CRLF)

;----------------------------------------------------------------------------------------
Sleep(15000)    ;Need to disconnect at this point so we can see what happens next!!!
;----------------------------------------------------------------------------------------

$RunFrom = EnvGet("Sessionname")
ConsoleWrite("Disconnected SessionName = " & $RunFrom & @CRLF & @CRLF)

;After Lock, again get session name and session state and write to console
Local $iPID = Run('"C:\Windows\System32\qwinsta.exe" ' & @UserName, "", @SW_HIDE, 2)
ProcessWaitClose($iPID)                                             ;Need to wait for it to finish before we get the StdOutput values

$sOutput = StdoutRead($iPID)                                        ;Retrieve whatever returned
ConsoleWrite("Disconnected StdOutRead = " & @CRLF & $sOutput & @CRLF)

 

Below is what i'm seeing returned by the script.  What I need is just the STATE field.

From RDP:

Active SessionName = RDP-Tcp#0

Active StdOutRead = 
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
>rdp-tcp#0         MyUsername                3  Active  rdpwd               




Disconnected SessionName = RDP-Tcp#0

Disconnected StdOutRead = 
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
>                  MyUsername                3  Disc

 

 

From Citrix:

Active SessionName = ICA-CGP#9

Active StdOutRead = 
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
>ica-cgp#9         MyUsername               43  Active  wdica               



Disconnected SessionName = ICA-CGP#9

Disconnected StdOutRead = 
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
>                  MyUsername               43  Disc

 

Thanks,

Mike

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By PoojaKrishna
      Hi,
      I am trying to print items from Outlook in a Citrix machine. I am printing the items into PDF files using ‘Microsoft Print to PDF option’. I am using OutlookEX.au3 for printing items.
      Everything is working fine except handling the ‘Save Print Output As’ dialog appearing while trying to print the file to PDF.
      I have set the default printer to ‘Microsoft Print to PDF’ from the control panel ( Control Panel\All Control Panel Items\Devices and Printers) and using the following method to print the item.
      _OL_ItemPrint($oOutlook, $OL_Item) ;print item I am not able to handle the ‘Save Print Output As’ dialog initiated by the print statement in the Citrix machine. The WinActive method always returns false. I have tried with ControlSetText, ControlClick and Send methods also.
      Can anyone please help?
      Func _SavePDF($sFilePath) WinActivate ( "Save Print Output As", "") WinWaitActive ( "Save Print Output As", "",5 ) If WinActive("Save Print Output As") Then sleep(500) Send($sFilePath) sleep(500) Send("{ENTER}") sleep(500) EndIf EndFunc;=>_SavePDF  
    • By ajorgensen
      Hi, I am trying to get logged into our Citrix Storefront, we had this working on an older version but it was using "forms" and now it has changed.
      Here is the html for logon page, I need to select the username, password and then click the login button. I have been able to get to this page but do not know how to population these variables. Thanks for any help.
       
      citrix-logon.txt
    • By argumentum
      About This File
      I use RDP a lot, and is not uncommon to run another session again, closing the prior connection that was minimized.
      The solution:  See if the window exists. If it does, restore it, else, run it.  
      And this is the support topic for RdpRunner.
      so, if you need help with this, this is the place  
      The only question that come to mind is: What is a RDP file ?, and that, is better answered by searching https://www.google.com/search?q=rdp+file
       
    • By argumentum
      I use RDP a lot, and is not uncommon to run another session again, closing the prior connection, when minimized.
      The solution?, see if the window exists. If it does, restore it, else, run it.
    • By RestrictedUser
      Hello Guys and AutoIt Scriptwriters!🎉❤️
      I've created a script to notify to me if RDP main IP changed then send a message via Telegram bot to me
      But some of my RDP's Main IP are @IPAddress1 or @IPAddress3 or Public IP Address...
      I want to detect automatically the IP that windows client can run RDP to remotely control
      This image can help you that what i say, there are three RDP with specified IP, i want to run script in these RDP's then capture those IP's changes then notify me via Telegram bot

×
×
  • Create New...