Question

Locked

Detecting if a program is being run in terminal services

By Slayer_ ·
Basically I want to know if my program is being run in a terminal server session.

So far, my research has told me that


Const SM_REMOTESESSION As Long = &H1000
Const SM_REMOTECONTROL As Long = &H2001


GetSystemMetrics(SM_REMOTESESSION)
Tells me if your program is running in an RDP session, but not Terminal Server specifc, any RDP session, so not useful.

GetSystemMetrics(SM_REMOTECONTROL)
I have yet to figure out how to get a value from this, I tried on a terminal session and it returned 0, I suspect it has something to do with Controlling someone elses remote session through terminal services. I cannot seem to get this to work to test this, but it is apperently not what I want.


To Summarize, I want to know when My app is running in a terminal session, not just remote desktop. A remote desktop session to a normal machine (IE a workstation) should be different from a terminal session'd RDP. I want to know when its the terminal session under terminal services.

If it helps anyone, I am coding this under VB6 and am fairly skilled with Windows API.

Any help would be appreciated.

This conversation is currently closed to new comments.

12 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Terminal...

by MAEX In reply to Detecting if a program is ...

...services is what RDP connects to.

Terminal services is present in Admin mode and Application Mode.

XP supports 1 connection admin mode.

W2000 and W2003 support 2 connection admin modes, plus Application Mode.

In either case I would use Terminal Services Manager to verify that your application is being executed.

Collapse -

Wait what?

by Slayer_ In reply to Terminal...

What? anyone can enable RDP on an XP pro machine, but your only licenced for one person to use it at a time. Terminal services is a Windows server feature, that, if you have licenses for, can allow any number of users to RDP into your server and connect and use it like its their own machine.
The problem comes in is that one of these terminal users cannot install software to the other users. you have to be a special admin user to do this. My program cannot be run as this special admin, the installation needs to be done manually. The problem is the "black box" for the application doesn't recognize it cannot install, so it tries, and fails, and actually corrupts the entire server. Saddly providing a manual that says don't do this, doesn't work out, so my program needs to know if it is running in the environment that will not work. That is, a true terminal service session.


The full situation is I have servers to use this one, with terminal sessions to litiritatly 100's of users simultainiously. Naturally none of them have permissions to install anything. So there is an admin user. This admin user can run installs in an "install mode" of sorts. This mode however bombs out our installation so baddly it corrupts the server. This only happens if the install is automated, if they do it manually, there is no problem. Now as many people know, the IT people running these servers are generally not too bright, and usually won't read a manual to find out they shouldn't run it automated. So they just do it, and this happens.
I created the automated portion of this installation, and I want to make it smart enough to know it cannot install in such an environment.
It is perfectly safe to install over RDP to any normal machine that is not running terminal services. Infact its done fairly often as installs can be from one side of the province to the other.
So I need a way of distinguishing the two.

Collapse -

What the poster is saying is that by default

by CG IT In reply to Wait what?

Windows Server, XP etc allows only 2 concurrent connections for administrative mode via terminal services [remote admin mode] That appears to be what your output is showing.

The connection for remote admin mode is RDP.

If you run an application on a terminal server and the terminal server is running in application mode, you have CALs for each connection. The # of connections that can be made if the amount of CALs you have.

With Windows Server 2000, you use to have to specify what mode your installing the server in, application mode or admin mode. With Windows Server 2003, you can add a terminal services role, add enough CALs for the # of users who will access the application. No problem. This terminal services is not the same as remote admin via terminal services.

Collapse -

That makes some sense but

by Slayer_ In reply to What the poster is saying ...

It's not really what I'm asking :).

How can my app tell if it is in such an environment? The one system metric seems to return true whenever you are RDP'd into a system, so while this is correct for a server, it is incorrect for a workstation. Usually we will run workstation installs remotely as they can be physically located a good 500km's or more away.

So simply, it needs to be able to install on Server 2003 if it is being used as a normal server, AKA, file and or database, it needs to work on server 2003/2005 as a workstation (Don't ask why these are workstations), and it needs to work remotly to XP and 2000 machines that are workstations. It should not work for a terminal services server.

Collapse -

your app can't tell if it's running on Terminal Services

by CG IT In reply to That makes some sense but

to answer your question. An application [client app] doesn't care. It's whether it can find the back end program [DB] to present information to the user via the client app. The Computer cares because of how it will make the connection to the back end DB .

You can monitor RPC calls. RDP [remote desktop] calls can also be monitored.

Collapse -

Alright thanks, this tanks this idea then

by Slayer_ In reply to your app can't tell if it ...

That sucks but its acceptable, the new idea of checking if the terminal services license service EXE exists on the C drive seems to be working. It won't disable my automation but it does flag it as a possible problem and recommends against it.

Collapse -

Found different Way, would still prefer API method

by Slayer_ In reply to Detecting if a program is ...

The new idea is to search for either the service "Terminal Server Licensing"
or if this file "C:\windows\system32\lserver.exe" exists.

However both could techincally be true and have teminal servicing off, so I would still prefer an API method.

Well, now to go look if I can get a list of running services.

Collapse -

Try...

by MAEX In reply to Detecting if a program is ...

...this:

All versions of Microsoft Windows XP include the Terminal Services service. Many different components in each version of Windows XP use this service. This article describes which components use the Terminal Services service.

http://support.microsoft.com/kb/281311

As to Windows Server 2003 TS Manager...
http://technet.microsoft.com/en-us/library/cc786615.aspx

As to looking for XP and 2k3 clients with your TS Manager...
http://support.microsoft.com/kb/281307

If you look around MS Technet site, you'll find lot's of answers. Sometimes its not perfect but will point in the right direction.

Collapse -

This is....

by Slayer_ In reply to Try...

Not quite right, its interesting, but it doesn't completely help me. Though I now realize that terminal services is almost just an extension to what already exists in Windows.

So it tells me I need to angle this more to figuring out if it is installed and activated.

Thanks though

Collapse -

The SESSIONNAME environmental variable

by techrepublic In reply to Detecting if a program is ...

will give you the information.

If environ("SESSIONNAME") == "CONSOLE" then the current program is being run in a terminal services console.
If environ("SESSIONNAME") == "RDP#" then the current program is being run in a RDP session.
If environ("SESSIONNAME") == "" then the current program is not running in terminal services.

Kind of a hack but it works.

Back to Networks Forum
12 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums