When a client is installed, it is not allowed to be started multiple times. However, when more than two clients are installed, it is allowed to run simultaneously, and each client can only run once.
First, judge the number of processes running. when the process is not running, it is started. When the number of processes running is greater than 1, read the path of each process and determine whether the path is repeated. If there are duplicates, it is not allowed to start, then run and start.
# Region determine whether the system is started
String STR = "";
STR = system. Diagnostics. process. getcurrentprocess (). processname;
System. Diagnostics. Process [] myprocesseslist = system. Diagnostics. process. getprocessesbyname (STR); // obtain the specified process name
Int listlength = myprocesseslist. length;
String [] processesfile = new string [listlength];
If (listlength> 1)
{
For (INT I = 0; I <listlength; I ++)
{
System. Diagnostics. Process PRC = myprocesseslist [I];
Processesfile [I] = PRC. mainmodule. filename;
}
Bool loginflog = false;
For (int K = 0; k <listlength; k ++)
{
For (Int J = k + 1; j <listlength; j ++)
{
If (processesfile [k] = processesfile [J])
{
Loginflog = true;
Break;
}
}
}
If (loginflog)
{
MessageBox. Show ("the program has been started", "prompt", messageboxbuttons. OK, messageboxicon. Error );
Return;
}
}
# Endregion