The above is a class that detects repeated program running on the Internet, but it does not feel very useful. It seems completely unnecessary to use APIs, so I wrote a function at night, after testing, the program can still be detected multiple times under multiple users. Of course, if the program name is changed, it can still run again, but this method is afraid that there is no good way, unless it is in.. NET environment or the registry, but it does not seem necessary.
- If (appinstance ())
- {
- MessageBox. Show ("Warning: The program is running! Do not open the program again! "," System prompt ", messageboxbuttons. OK, messageboxicon. Warning );
- Return;
- }
- Public static bool appinstance ()
- {
- Process [] myprocesses = process. getprocesses ();
- Int I = 0;
- Foreach (process myprocess in myprocesses)
- {
- If (myprocess. processname = process. getcurrentprocess (). processname)
- {
- I ++;
- }
- }
- Return (I> 1 )? True: false;
- }
In fact, check the process name in the process. If there is more than one, return true