Use WshPipe to run the command directly. It returns the output in a string (or my updated version, which returns an array. Change the command to
 Code:
%COMSPEC% /c query session %USERNAME% | find "%USERNAME%"
, which will return just the line containing the user name. This simplifies trying to find line 2. \:\)

Now you can simply use SubStr($line, 2, 3) to return the connection name part.

If you use the standard WSHPIPE UDF, understand that it returns one large string with both STDOUT and STDERR in it. My updated version (on my web site) returns an array of arrays, so you can reference line 1 of STDOUT as $array[0][0] - the first index is 0 for STDOUT and 1 for STDERR, and the second index is the zero-based line number.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D