Finding Process Path
-
Hi all, How can i find out process path? i am using following code for getting process file name. i need to get the path of that file also. Can any one help me?? Process[] arrProcesses = Process.GetProcesses(); for (int i = 0; i <= arrProcesses.Length - 1; i++) { Process objProcess = arrProcesses[i]; if (objProcess.ProcessName == "WINWORD" && !(objProcess.MainWindowHandle == IntPtr.Zero)) { string FileNameDefault = objProcess.MainWindowTitle; string[] str1; str1 = FileNameDefault.Split('-'); // System.IO.Path pt=objProcess.exe FileNameDefault = str1[0]; } } Regards Lijo
-
Hi all, How can i find out process path? i am using following code for getting process file name. i need to get the path of that file also. Can any one help me?? Process[] arrProcesses = Process.GetProcesses(); for (int i = 0; i <= arrProcesses.Length - 1; i++) { Process objProcess = arrProcesses[i]; if (objProcess.ProcessName == "WINWORD" && !(objProcess.MainWindowHandle == IntPtr.Zero)) { string FileNameDefault = objProcess.MainWindowTitle; string[] str1; str1 = FileNameDefault.Split('-'); // System.IO.Path pt=objProcess.exe FileNameDefault = str1[0]; } } Regards Lijo
-
objProcess.MainModule.FileName Edit: Suggestion: If you are searching for only Winword processes you can use Process.GetProcessesByName to avoid the loop and checking for the particular process name
modified on Monday, March 2, 2009 9:46 AM
ABitSmart wrote:
avoid the loop
GetProcessesByName() returns an array, just like GetProcesses() does; it probably will be a shorter array, but you may still want to enumerate it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:58 AM
-
ABitSmart wrote:
avoid the loop
GetProcessesByName() returns an array, just like GetProcesses() does; it probably will be a shorter array, but you may still want to enumerate it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:58 AM