Is there anyway, in a program, to detect if a program is being run from inside a remote desktop session or if the program is being run normal in .NET 2.0? What I\'m trying t
Well, I had a similar issue a few days ago. What I did to resolve it was took advantage of the fact that some Remote Desktop Application use a known default port, at least VNC and/or Microsoft Remote Desktop Connection. So I created a method which tells if the port is being used, as follows:
/* Libraries needed */
using System.Linq;
using System.Net.NetworkInformation;
/*....
....
....*/
private static bool IsPortBeingUsed(int port)
{
return IPGlobalProperties.GetIPGlobalProperties().
GetActiveTcpConnections().
Any(
tcpConnectionInformation =>
tcpConnectionInformation.LocalEndPoint.Port == port
);
}
Remember to put the using statements with the libraries at the beginning of the file where the method is.
You just have to pass for example a parameter like the 3389 port which is the default port for Remote Desktop Connection, or the 5900 port which is the default port for VNC Connections.
The method is created with C# 4.0 features but it can perfectly be done with and older version of C#.Net or Visual Basic.
This worked for me since I only needed to check for the two application I mentioned before.
I hope it can help.