Check whether executable file is running or not

a1jit

Regular
Joined
Aug 19, 2005
Messages
89
Hi Guys,

Is there any way to implement the logic below

Check whether Test.exe is running or not. If its running, dont do anything.
If it is not running, launch it


Thank you very much
 
C#:
System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("Test");
if(procs.Length >= 1)
	System.Diagnostics.Process.Start("Test.exe");
should get you started
 
wOWOWO..Excellentttt...thax a lottttt...

But im confused a little

if procs.Length == 0 , then we should start up Test.exe ..

Normally if the file is not running, meaning procs.Length will return 0 right?

And im confused about another thing..

Whenever i put this code and create new project as a "Windows Service",
No matter the executable is running or not, it always says that its running. Although it is not running..Pretty weird..

If its windows application, when i debug, it works well..

But when i create a service, it does not..

Any idea?
 
Last edited:
Back
Top