Page 1 of 1 1
Topic Options
#210868 - 2015-10-28 09:54 PM Detecting session type
Fowzzie Offline
Fresh Scripter

Registered: 2015-10-06
Posts: 6
Loc: UK
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?

Top
#210869 - 2015-10-28 10:51 PM Re: Detecting session type [Re: Fowzzie]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4473
Loc: USA
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

Top
#210871 - 2015-10-29 01:52 PM Re: Detecting session type [Re: Allen]
Fowzzie Offline
Fresh Scripter

Registered: 2015-10-06
Posts: 6
Loc: UK
Error

Edited by Fowzzie (2015-10-29 03:14 PM)

Top
#210872 - 2015-10-29 01:56 PM Re: Detecting session type [Re: Fowzzie]
Fowzzie Offline
Fresh Scripter

Registered: 2015-10-06
Posts: 6
Loc: UK
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?

Top
#210873 - 2015-10-29 04:59 PM Re: Detecting session type [Re: Fowzzie]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4299
Loc: New Jersey
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

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 49 anonymous users online.
Newest Members
ROBECCO80, TsuyoiSaigai, a5tr0, FoolZero, DaveE
17657 Registered Users

Generated in 0.03 seconds in which 0.011 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org