The System.Diagnostics.Process class used in the SHelton example gives you access to the processes running on the same machine not on the different machines.
The above example is enough to detect multiple instances on the SAME process running on the SAME machine.
An object of System.Diagnostics.Process class gives you all you need about a process.
Here is another way to detect multiple instances using Mutex object:
public class MainForm : System.Windows.Forms.Form
{
private static Mutex _AppMutex;
// ...
}
[STAThread]
static void Main()
{
_AppMutex = new Mutex( true, "My application" );
if( _AppMutex.WaitOne( 0, false ) )
{
Application.Run( new MainForm() );
}
else
{
System.Windows.Forms.MessageBox.Show( "Another instance of My application is already running."

;
}
}
For the Terminal Server you should implement something to manage that on the machine where resides your exe.
A potential solution:
- Let be MyApp.exe on a machine (server)
- Create a service named for example: MyApp_Service.exe and install it on the server with MyApp.exe
- Create a simple application for example: MyApp_Client.exe and it will do:
-identify the user
-connect to the MyApp_Service.exe
-send a request (tcp.Send()) to start the MyApp.exe. The MyApp_Service.exe read the request and is looking on the server how many instances of the MyApp.exe are running and takes actions.
-When MyApp_Service.exe starts the MyApp.exe it passes a keyword to the MyApp.exe
- MyApp.exe will check this kwyword first. If it is not recognized then the MyApp.exe exits.
That means you never start directly MyApp.exe.
Only MyApp_Service.exe is doing that upon an identified request.
If someone clicks on the MyApp.exe on the server that will not work because the keyword, so you can manage number of instances.
There are also other solutions, for example using a centalized and safe logging file.
-obislavu-