bockjacob


Code Snippet

System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
for (int i = 0; i < myProcesses.Length; i++)
{
string processName = myProcesses[i].ProcessName;
processName = Path.GetFullPath(processName);
richTextBox1.AppendText(processName);
richTextBox1.AppendText(System.Environment.NewLine);
}


I am having trouble showing the full path of a running process. I am trying to populate a rich text box with the full paths of all running processes such as "C:\WINDOWS\system32\notepad." I can get a list of all the running processes just fine, but when I try to do the fullpath command, I get the path of the debug folder of the project.



Re: Trouble showing full path of a running process

OmegaMan


The System.IO.Path.GetFullPath, to quote MSDN,

Returns the absolute path for the specified path string.

You are passing in a process name that gets appended to the path where your application is running. GetFullPath cannot divine running processes to determine where the exe may sit on the hard drive. See Path.GetFullPath Method for why it is doing that. As to a running process I don't believe it is associated with a directory, possibly a working directory may be set...check, from your code


Code Snippet


myProcesses[i].StartInfo.WorkingDirectory








Re: Trouble showing full path of a running process

Thomas Danecker

The process name may be any string. Use the following to get the filename of the process:

Code Snippet

myProcesses[i].MainModule.FileName







Re: Trouble showing full path of a running process

bockjacob

Thanks Thomas, it worked perfectly.