I am working on a java based desktop application. One requirement is that if application is running and user try to start the application again it should do something like show some alert etc.
I used file for this, when user run the app it add some text into a file and save it somewhere on the local system and when user try to run the app again i check the file and handle the situation accordingly, but there are some issue with this, like if application is abnormally terminated i am not able to remove that file and in that case when user tries to run the app system shows alert that application is already running but actually app terminated abnormally.
I did some R&D and found that i can read windows task manager list and then i can get and check my app if it is running. it was working fine but during testing i got an issue i-e there is a software/utility in windows named "tasklist" go to "start --> run" and type tasklist it will show you the task list. if this utility is not installed on your system or removed/corrupted for some reason then this will not work and same issue occur that user can start the application more then one time. Here is code to access the taskmanager items
Process p = Runtime.getRuntime().exec(
System.getenv("windir") + "/system32/" + "tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(
p.getInputStream()));
while ((line = input.readLine()) != null) {
/*
Make the comparison here and show alert.
*/
}
Question: What is a good way to check if the app is already running? I am using Java for application, and advanced installer to create the installer of the application.