One approach is to use WMI and the System.Management namespace. The following code creates a SelectQuery instance to find all instances of the WMI class Win32_Process that represent a process called explorer.exe. The query also specifies that the Name and Executable path for each instance should be retrieved.
Then it creates a ManagementSearcher instance to iterate through those results and prints out the name and executable path of each instance.
String[] properties = { "Name", "ExecutablePath" };
SelectQuery s = new SelectQuery ("Win32_Process", "Name = 'explorer.exe' ", properties);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(s);
foreach (ManagementObject o in searcher.Get()) { Console.WriteLine("{0}: {1}", o["Name"], o["ExecutablePath"]); }
How to get the path of a process
Thaedrys
foreach (Process theProcess in processList)
{
Console.WriteLine("Name: {0} Path: {1}", theProcess.ProcessName.ToString(), theProcess.MainModule.FileName.ToString());
}
Hemanth
One approach is to use WMI and the System.Management namespace. The following code creates a SelectQuery instance to find all instances of the WMI class Win32_Process that represent a process called explorer.exe. The query also specifies that the Name and Executable path for each instance should be retrieved.
Then it creates a ManagementSearcher instance to iterate through those results and prints out the name and executable path of each instance.
String[] properties = { "Name", "ExecutablePath" }; SelectQuery s = new SelectQuery ("Win32_Process",
"Name = 'explorer.exe' ",
properties); ManagementObjectSearcher searcher =
new ManagementObjectSearcher(s); foreach (ManagementObject o in searcher.Get())
{
Console.WriteLine("{0}: {1}", o["Name"], o["ExecutablePath"]);
}
Alex Paterson
It's not perfect, but you can try the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
HTH,