How to detect the launched appliction?
-
Hi All, I would like to know, how can I detect whether an application is already launched? I need to enable some function according to this checking, can some people help? thanks so much.
The preliminary question is: how do you identify your app? You could use
Process.GetProcessesByName()
to check for a specific process name; process names normally get derived from the EXE's file name (which can easily be modified!). A more reliable approach, if you are the author of the app, is by using a system resource (e.g. a Mutex) with a chosen system-wide name; you then check for the existence of that Mutex. This is how "single instance applications" normally do it. You may want to read this: A Pure .NET Single Instance Application Solution[^] or some similar article. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hi All, I would like to know, how can I detect whether an application is already launched? I need to enable some function according to this checking, can some people help? thanks so much.
-
The preliminary question is: how do you identify your app? You could use
Process.GetProcessesByName()
to check for a specific process name; process names normally get derived from the EXE's file name (which can easily be modified!). A more reliable approach, if you are the author of the app, is by using a system resource (e.g. a Mutex) with a chosen system-wide name; you then check for the existence of that Mutex. This is how "single instance applications" normally do it. You may want to read this: A Pure .NET Single Instance Application Solution[^] or some similar article. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Thanks for your infomation, Luc. I'm using your approach, and it works fine. I just got another question, if the PC is a remote server that different user may login to the server and launching the same application. May I use the same function to detect what specific user is launing the application ? thanks