I need to know whether a process is already running but I don't want to hardcode its name. I'd rather derive it from the *.exe
so I performed some experiments and created a simple console application where I set the assembly name in project properties to foo
and then renamed the foo.exe
to bar.exe
. I checked the running processes and indeed it was bar
that was running.
Is it by design and I can rely on this behavior or can a process have a different name from the exe
and does it apply to all kinds of exe
files or only to .NET assemblies?
You can't change the image name of the process. That is set by Windows and not changeable. It will use the name of the executable to set it, so it is safe to use.
Instead of using the process to get the executable name, you could simply use the assembly name from .NET:
System.AppDomain.CurrentDomain.FriendlyName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With