You can create file at specific location in program load if not exists if exists it means that the application running show to the user the messagebox "can't dupl....." in form closing remove the file...
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
I have a similar issue, but my users are not actually starting the program. There is a shortcut to the program in the windows startup folder. After a few days of running the program will have multiple processes. What could be causing this if the users are not actually clicking on the .exe?
This is my first C# program, and all it does is monitor two other programs to make sure they are on at all times.
Sailor_Jerry
Junior Poster in Training
88 posts since Aug 2005
Reputation Points: 13
Solved Threads: 2
Use this sample...
Process[] processes = Process.GetProcessesByName("C");
foreach (Process p in processes)
{
MessageBox.Show("Can't duplicate run this program,it is already running in the background.", "can't run again", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
Some interesting answers. I've always used this method:
Single-Instance Application
It's obviously not fool-proof because changing the title of a running application is not that hard.
Something else you can do is if you can get the location of the running process you are comparing, create a new FileInfo class (I think) and compare the internal name of the file. Internal names are not as easy to change.
It's late at night and I didn't double check so forgive me if the above info is a little off
vckicks
Junior Poster in Training
58 posts since Jun 2008
Reputation Points: 11
Solved Threads: 9
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190