Fowzzie
(Fresh Scripter)
2015-10-28 09:54 PM
Detecting session type

I've created a script the detects a users session type (RDP or Console) and it works fine running simply be clicking the script but when deploying using GPO from 'User Configuration\Windows Settings\Security Settings\Scripts\Logon' it doesn't appear to be able to get the session type.

I've tried the following

$sessionname = ExpandEnvironmentVars(%sessionname%)

and

@LOGONMODE

Can anyone tell me why these don't appear to work when used on GPO but do from manually running.

I think it's something to do with the way GPO executes scripts run as say system but this is only a guess.

Does any have any other solutions to find out if the logging on user is running in an RDP session or Console?


AllenAdministrator
(KiX Supporter)
2015-10-28 10:51 PM
Re: Detecting session type

It is running in the context of the system user.

You could possibly use the RunAsInteractiveUser UDF to immediately run another script containing the sessiontype code along with mapping drives, printers etc that is specific to the user. If you choose to go this route, please post your results and or comments in the following thread. It has been well tested now, but all comments are welcome.

RunAsInteractiveUser -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=198514#Post198514

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1


Fowzzie
(Fresh Scripter)
2015-10-29 01:52 PM
Re: Detecting session type

Error

Fowzzie
(Fresh Scripter)
2015-10-29 01:56 PM
Re: Detecting session type

I’ve been thinking I could use query session to get the information using the command 'query session %username$' and dumping this to a file to ready line to as the output looks like this;-

SESSIONNAME USERNAME ID STATE TYPE DEVICE
>console User.Name 1 Active

I could have a function to read line to second, third and fourth cherishers to return 'Con'

I've created to code to output the file but having issues getting the code together to read line 2 characters 3, 4 and 5. Any ideas?


Glenn BarnasAdministrator
(KiX Supporter)
2015-10-29 04:59 PM
Re: Detecting session type

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