Assigning part of result to a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
steelrodman
Posts: 3
Joined: 31 Jan 2012 09:07

Assigning part of result to a variable

#1 Post by steelrodman » 31 Jan 2012 09:20

Firstly sorry for the poor title.

I am trying to write a batch file that will logoff Citrix (Terminal Services) connections.

The username will be passed to the batch file from an external application. I need to use this to logoff the session from the batch file.

Code: Select all

logoff username /Server:server1
should work, but it only works for me if i specify the ID (logoff ID /server:server1).

Is there a way I can use QWINSTA (or similar), and assign the ID into a variable? This way I can run my logoff command.

Example:

Code: Select all

qwinsta USERNAME /SERVER:citrixserver
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 ica-tcp#6534      UserOne                  3  Active  wdica


The code should store "3" in a variable.

Any suggestions welcome.
Thank you.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Assigning part of result to a variable

#2 Post by Squashman » 31 Jan 2012 09:27

I don't have a Citrix environment but I am thinking this will get you the userid into a variable.

Code: Select all

for /F "skip=1 tokens=3 delims= " %%I in ('qwinsta USERNAME /SERVER:citrixserver') do set Userid=%%I

steelrodman
Posts: 3
Joined: 31 Jan 2012 09:07

Re: Assigning part of result to a variable

#3 Post by steelrodman » 31 Jan 2012 09:36

This works perfectly!

Thanks very much for the solution, and speedy reply.

Post Reply