how to determine if real console or rdp console

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

how to determine if real console or rdp console

Post by matthiasR » Wed Jun 17, 2009 8:59 am

Hi,

is there a way to find out if the Administrator is logged on directly to the console of the server or via rdp to a console session.

Tried Marcus´ script to determine if console session or remote session. But that always reports console. Maybe this depends on that the admin connects to a console session.

I want to avoid that Macroscheduler start on both session the same script.

So, is there a way to find that out in MacroScheduler?

Regards,

Matthias

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Having same problem

Post by gdyvig » Wed Jun 17, 2009 4:13 pm

I'm having the same problem with one of my scripts. Not solved yet, but here is what I've found so far:

http://www.tech-archive.net/Archive/Win ... 00157.html

This site suggests using GetSystemMetrics to determine whether you are logged on a console or remote session. Other posts in this forum show how to use GetSystemMetrics. This site proposes using QWINSTA if you have not yet connected.

Another thing I noticed. If you run Task Manager with "Show processes from all users" turned OFF, the console session will display additional processes running as services. However you probably rather use a method that does not require displaying a GUI.


Gale

P.S. Believe this is the script Matthias tried to use
http://www.mjtnet.com/usergroup/viewtopic.php?p=11176
Last edited by gdyvig on Wed Jun 17, 2009 4:52 pm, edited 3 times in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Jun 17, 2009 4:36 pm

In a non-remote situation I handle this problem by using compiled scripts started by a starter script that checks for the process (using vbscript code that has been posted on here many times) before starting the real script.

matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Post by matthiasR » Thu Jun 18, 2009 9:36 am

Hi,

thanks to all who replied.

After playing around a little bit, i decided to use QWINSTA.exe for that.

My script now detects, if the scheduled script is exceuted under console or RDP console. So i can avoid, that a script is executed the same time under console and rdp console.

Here under Windows 2003 server and Vista it works.

Code: Select all

let>targetFile=c:\rdptest.txt

RunProgram>cmd /c \windows\system32\qwinsta.exe %user_name% > %targetFile%
let>i=2
label>start
ReadLn>%targetFile%,i,tLine
if>tLine=##NOFILE##,NoFile
if>tLine=##EOF##,NoUser
midstr>tLine,1,8,tString
midstr>tLine,1,4,tString2
if>tString=>console,ConsoleMode
if>tString=>rdp,RdpMode

let>i=i+1
goto>start


label>ConsoleMode
messagemodal>Console Mode
Remark>put here the code, which should be executed in console mode
goto>finish

label>RdpMode
messagemodal>RDP Mode
Remark>put here the code, which should be executed in rdp mode
goto>finish


label>NoFile
Remark>Here you could place the code, which shall be executed,because QWINSTA was able not create the file
goto>finish

label>NoUser
goto>finish

label>finish
Regards,

Matthias

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Jun 18, 2009 3:34 pm

ReadLn>%targetFile%,i,tLine
if>tLine=##NOFILE##,NoFile
if>tLine=##EOF##,NoUser
midstr>tLine,1,8,tString
midstr>tLine,1,4,tString2
if>tString=>console,ConsoleMode
if>tString=>rdp,RdpMode
Just curious what you are doing with tString2?
Should the last IF command be checkiing tString2 vs. tString ?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Post by matthiasR » Thu Jun 18, 2009 4:32 pm

Hi Bob,

it should be tString2 in the last IF command, although tString2 is actually not needed, as QWINSTA produces an output, where several spaces are between sessionname and username.

I use it anyway. Maybe there are other versions of QWINSTA, which do not have that additional spaces.

Regards,

Matthias

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts