Allowing users to reset their own Citrix session

From time to time our Citrix users end up with multiple sessions on our Citrix farm, especially when accessing the farm via Citrix access gateway and they loose connectivity. Most of these are fixed by setting sessions in the disconnected state to be automatically reset after 15 mins. (We allow this time  incase users are moving to a meeting room for example).

The big problem for us is that you can’t run multiple instances of Lotus Notes, so the disconnected session needs to be reset before the user can fire up Lotus Notes again, otherwise they will see an error like:

“You cannot use the Administration program while the Domino Server is running. Either shut down the Domino Server (buy keep the file server running) or choose the icon labeled ‘Lotus Notes’ instead.”

In order to try and make things a bit easier on the helpdesk, I created a script that will allow users to reset their own Citrix sessions. If you want to use it you’ll need to populate the first array with a list of all the servers in your farm, then create a shortcut:

cscript /nologo citrixreset.vbs

I’ve set mine to run minimized so that they don’t see random command windows popping up.

It should also be noted, that the script resets any disconnected sessions first, so that it can still carry on and kill the active one at the end! I know it’s not the slickest of scripts (Lots of splitting arrays and capturing command output), but I couldnt find any nice objects to do it properly with!

 citrixServers = array("CXS38", "CXS39", "CXS40", "CXS41")

Set objShell = CreateObject("WScript.Shell")

Sub resetSession(s)
    count = count + 1
    sessionID = trim(mid(s,48,5))
    citrixServer = trim(mid(s,1,6))
    wscript.echo "RESET SESSION " & sessionID & " /SERVER:" & citrixServer
    Set oExec = objShell.Exec("RESET SESSION " & sessionID & " /SERVER:" & citrixServer)
End Sub

userName = objShell.ExpandEnvironmentStrings("%UserName%")

For Each citrixServer In citrixServers

    wscript.echo "QUERY SESSION " & userName & " /SERVER:" & citrixServer
    Set oExec = objShell.Exec("QUERY SESSION " & userName & " /SERVER:" & citrixServer)

    Do While oExec.Status = 0
        WScript.Sleep 100

    Do While oExec.StdOut.AtEndOfStream <> True
        sessionOutput = sessionOutput & vbCrLf & citrixServer & oExec.StdOut.ReadLine


count = 0
sessions = split(sessionOutput, vbCrLf)

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Disc") then wscript.echo session

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Active") then wscript.echo session

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Disc") then resetSession(session)

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Active") then resetSession(session)

msgbox "Reset " & count & " Citrix session(s) for " & userName


  • XRumerTest commented on September 18, 2009

    Hello. And Bye.

  • Freshy commented on November 20, 2009


    I am testing out your script in our Citix enviornment and everything runs but nothing actually gets reset. The script even finds all the open sessions but never resets them. Do you have any idea as to why this might be?


  • Geoff Kendal commented on November 23, 2009


    The script basically works by performing the following commands at the command prompt as the user running the script:



    You could try running them manually, to see if you can list your sessions on a server with the first command, and reset a specific session with the second command. Obviously you’ll need to replace my username and the CXS39 server name with your own. The session number used in the reset command will be one listed in the QUERY SESSION output.

    My method of getting the session ID and server name is quite crude (lines 07/08), it might be that your version of query session returns a slightly different formatted output to my environment.

    A few things for you to try there… Let me know how you get on!

  • Matt Rowney commented on June 24, 2014


    I had the same problem, it turned out that the data that was trimmed in lines 7 and 8 did not match. this was because our server names had more characters as did our usernames.

    I had to increase some of the numbers within the brackets to accomodate

    Matt Rowney

  • Chris Haynes commented on October 29, 2015


    I have amended the code to use within our company and it works, but only for people with usernames that are 10 characters or less. It will not work with any over that length.

    When I run the query manually, the following is output:

    ica-tcp#83 alishapatel 83 Active wdica

    I have narrowed this down to a problem with line 7 in the code, which in our case is set to the following:

    sessionID = trim(mid(s,43,19))

    I don’t understand why this works with shorter usernames and not the ones with over 10 characters, as the session ID is in the same posisiton?

    Can anyone advise how to rectify? I’ve tried playing with the numbers but no combination seems to pick up the Session ID when ran by the user with over 10 characters

    Thanks in advance,


Leave a Reply

Your email address will not be published. Required fields are marked *