3

I have a .NET application where I need to be able to disallow running it on a Terminal Services server for licensing reasons. I am aware of the SystemInformation API to determine if a program is running under a remote session (as detailed in this question for example). However, that API does not distinguish between an application running on a normal server which has the 2 allowed remote desktop sessions and a full-blown terminal server which might have 500 sessions running on it.

Is there a simple programmatic way that I can determine whether the application is running on a full-on terminal server?

I am fine with the assumption that more than 2 allowed sessions means a full-on terminal server, and I am also fine with P/Invoke if that's what's required.

Community
  • 1
  • 1
Matt Whitfield
  • 6,436
  • 3
  • 29
  • 44
  • I'm curious as to how this information would be helpful. I don't know of anything in the RDS API that exposes this. You could potentially check whether the server has RD licensing servers configured. – Dan Ports Aug 16 '13 at 23:11
  • @DanPorts - The information would be helpful because it's a business requirement that the software is not able to be used on a Terminal Services environment. – Matt Whitfield Aug 17 '13 at 21:09

1 Answers1

1

One way is to use the below code:

    string s = System.Environment.GetEnvironmentVariable("SessionName");

If the value of s is "Console", it could be running in terminal services. On the other hand, if the value is something like "RDP-Tcp#01", it is running under Remote Desktop.

shree.pat18
  • 21,449
  • 3
  • 43
  • 63