Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the process name always the name of the exe?

Tags:

c#

.net

windows

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?

like image 206
t3chb0t Avatar asked Feb 03 '16 10:02

t3chb0t


1 Answers

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
like image 73
Patrick Hofman Avatar answered Nov 14 '22 22:11

Patrick Hofman