[THIN] Re: session kill

  • From: Jason CitrixADmin <jasoncitrix@xxxxxxxxx>
  • To: thin <thin@xxxxxxxxxxxxx>
  • Date: Fri, 6 Jun 2014 10:42:28 -0400

So if I use the following:
@echo off

*for /f %%i in (m:\testselfclose\labfarmlist.txt) do (query user %USERNAME%
/server:%%i 2>NUL | find /i "%USERNAME%" > %TEMP%\%%i.txt*
*    FOR /F "tokens=3" %%j in (%TEMP%\%%i.txt) do @logoff %%j /server:%%i)*
*for /f %%i in (m:\testselfclose\labfarmlist.txt) do (query user %USERNAME%
/server:%%i 2>NUL | find /i "%USERNAME%" > %TEMP%\%%i.txt*
*    FOR /F "tokens=2" %%j in (%TEMP%\%%i.txt) do @logoff %%j /server:%%i)*

It will release hung (Active) and disconnected session


On Fri, Jun 6, 2014 at 10:09 AM, marcus <marcus@xxxxxxxxxxxxxx> wrote:

>
>
> Jason CitrixADmin wrote:
>
>> I found the following script that is supposed to handle disconnected
>> sessions, but I think it kills ALL disconnected sessions, not just those
>> belonging to a user.
>> Since I am not very good with scripts perhaps someone can verify, and
>> verify that it works across morethan one server.
>>
>> / Logoff Disconnected Sessions
>>
>> ' If you want to logoff active sessions as well, change the query to
>> include
>> ' cActive
>> On Error Resume Next
>>
>> Const cActive = 0
>> Const cDisconnected = 4
>> Const strComputer = "."
>>
>> Set objWMICitrix =
>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &
>> "\root\citrix")
>> Set colItems = objWMICitrix.ExecQuery ("Select * from Metaframe_Session
>> Where sessionstate = " & cDisconnected)
>>
>> For Each objItem in colItems
>> if (objItem.SessionID > 0) and objItem.SessionID then
>> objItem.Logoff
>> end if
>> Next
>>
>> /
>> /Set objWMICitrix = Nothing/
>>
> Hej,
> i've found the solution for a users leftover (reason may vary)
> disconnected sessions: in the line where the logoff is done:
> change tokens=3 to tokens=2
>
> logoff awaits either a session id or a session name.
> With tokens=2 disconnected sessions have the session id,
> active sessions have the session name.
>
> one more: i've stumbled upon an error when using "query user" and
> whitespace in the username. Switching to quser has fixed that for at least
> Srv 2003 R2. Weird but working
>
> cheers, Marcus
>
>
>
>
>
>>
>>     Hej,
>>
>>     first: many thanks, i've seen the script, tested and deployed it. As
>>     icon the red Powerbutton from Shell32.dll, a descriptive name - no
>>     room left for questions like "What's that for".
>>
>>     One Question / an observation i made: what about disconnected
>> sessions?
>>     As far as i've seen they aren't logged off.
>>
>>     cheers, Marcus
>>
>>  ************************************************
> For Archives, RSS, to Unsubscribe, Subscribe or set Digest or Vacation
> mode use the below link:
> //www.freelists.org/list/thin
> ************************************************
>

Other related posts: