How can I get the filename and sourcepath of a running process?
-
Hi, I am using something like this to get all my running processes:
Process\[\] processlist = Process.GetProcesses(); foreach(Process theprocess in processlist) { Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); }
My problem is that I want to know the filename (EXE) of a process, and the pathname it was started from. For example, if there is a process Notepad.exe running, I want to determine in which folder that file actually resides, i.e. something like "C:\Windows\system32\notepad.exe". How can I get that information? I already tried to get the member StartInfo. but it doesn't contain a link to the folder. How can I do this?
-
Hi, I am using something like this to get all my running processes:
Process\[\] processlist = Process.GetProcesses(); foreach(Process theprocess in processlist) { Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); }
My problem is that I want to know the filename (EXE) of a process, and the pathname it was started from. For example, if there is a process Notepad.exe running, I want to determine in which folder that file actually resides, i.e. something like "C:\Windows\system32\notepad.exe". How can I get that information? I already tried to get the member StartInfo. but it doesn't contain a link to the folder. How can I do this?
-
Hi, I am using something like this to get all my running processes:
Process\[\] processlist = Process.GetProcesses(); foreach(Process theprocess in processlist) { Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); }
My problem is that I want to know the filename (EXE) of a process, and the pathname it was started from. For example, if there is a process Notepad.exe running, I want to determine in which folder that file actually resides, i.e. something like "C:\Windows\system32\notepad.exe". How can I get that information? I already tried to get the member StartInfo. but it doesn't contain a link to the folder. How can I do this?
You can also use
theprocess.Modules[indexno].FileName // here indexno value of modules in the collection
:)
-
qwertz321 wrote:
theprocess.MainModule.FileName
Good one My vote 5. :)
-
You can also use
theprocess.Modules[indexno].FileName // here indexno value of modules in the collection
:)
that is much more expensive and in no way any better than what qwertz already provided. :|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
that is much more expensive and in no way any better than what qwertz already provided. :|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
that is much more expensive and in no way any better than what qwertz already provided.
Yes, that's why I vote 5 for qwertz and during writing my answer I have mention you can also use and code works very well. I just try to give an alternate answer. :)
-
You can also use
theprocess.Modules[indexno].FileName // here indexno value of modules in the collection
:)
RaviRanjankr wrote:
theprocess.Modules[indexno].FileName
We need to handle Exception in this case.
-
RaviRanjankr wrote:
theprocess.Modules[indexno].FileName
We need to handle Exception in this case.
MDNadeemAkhter wrote:
We need to handle Exception in this case.
Yes, in both cases either you are using MainModules or Modules you need to handle exception..
-
Luc Pattyn wrote:
that is much more expensive and in no way any better than what qwertz already provided.
Yes, that's why I vote 5 for qwertz and during writing my answer I have mention you can also use and code works very well. I just try to give an alternate answer. :)
Good its just look like a fire A complete + Answer :)
-
Good its just look like a fire A complete + Answer :)
ShilpaKumari wrote:
Good its just look like a fire A complete + Answer
Not a Matter some people Down vote or comment without testing code, which is not good in any corner. :)
-
ShilpaKumari wrote:
Good its just look like a fire A complete + Answer
Not a Matter some people Down vote or comment without testing code, which is not good in any corner. :)