views:

223

answers:

1

I would like to determine, from a .NET application, whether the current user (from System.Environment.UserName) is logged in to the machine physically, or via terminal services.

The use case is a startup program launcher. When I'm logging on to my development machine locally I would normally like a host of applications to be started automatically (Outlook, various notification area apps) but when I'm using terminal services to connect, it usually means I'm on call and dealing with an issue, and I want my system ready to go as soon as possible.

I'm guessing this is possible via WMI but I'm not familiar with the classes or queries to get it done.

+6  A: 

Check the SystemInformation.TerminalServerSession property

Thomas Levesque
That's much nicer than the solution I was about to post using p/invoke
Jeff Paquette
Actually this property does use P/Invoke internally (`GetSystemMetrics(SM_REMOTESESSION)` to be precise)
Thomas Levesque
Never even knew that class existed - what a plethora of useful info! Thanks!
David