By the title, I think it’s already clear that I would like to clarify how best to take the path to the running file. )

  • one
    No, unfortunately, it is not clear. What OS? Do you want to know the path to your file or to the executable file of some other process? If the other, then what about him known? - kirelagin
  • OS Windows. That is, there is an executable file, say calc.exe and I do not know where it is located. but this file is currently running and hanging in the processes. As for this process, find out the file location. ) - Eugene
  • So what do you know about this wanted file? Process name? - kirelagin
  • Yes, just the name of the process. - Eugene

3 answers 3

using System.Diagnostics; Process[] processlist = Process.GetProcessesByName("calc"); String result = ":("; foreach(Process p in processlist) { try { result = p.MainModule.FileName; break; } catch (Win32Exception) { } } System.Console.WriteLine(result); 
  • Only a small amendment: instead of viewing all the processes, it is better to find a list of processes by name: foreach (Process process in Process.GetProcessesByName ("calc")) - cy6erGn0m
  • Thank you very much. I'm going to try now. :) - Eugene
  • Yes, I already noticed). Thank. - kirelagin
  • @Eugene only now I do not know how to solve the problem with 64 bits ... It seems that way. - kirelagin
  • I need 32. ) You just need to do on 10 machines update the file of one. And do it on each machine separately - breaks. decided to automate. ) - Eugene

The only caveat - from the x86 applications will not be able to access the MainModule x64 applications.