Is there an easy way to pass a fully qualified path to an executable to System.Diagnostics.Process (or any other .NET process related class/object) and get back a Process object? GetProcessesByName doesn’t work with a path name or an executable, as follows:
//this returns a zero length array
a_process= System.Diagnostics.Process.GetProcessesByName(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
//this works, a_process[0] will be our process
a_process= System.Diagnostics.Process.GetProcessesByName("firefox")
Right now i’m doing it the long way (pseudo) :
target_executable= @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
get all active processes
for each process in all active processes
if process is not null
get filename from process module
return process if filename matches target_executable
is there a better way to do this?