1

I am creating a WPF application in C# that will monitor the processes running on a machine. I want to be able to collect a list of currently running processes and compare them to a list of processes I want to run. If the process I want to run is not yet running, then my application will start it.

I am having a problem getting the processes by name because I have numerous processes running off of one parent application (they are all started with different executable parameters,) so they all have the same process name. I also can't use process ID because there is no way for me to know the PID of processes started outside of my application. I need some way to differentiate the processes from one another both started in and outside of my application so that I can tell if they are already running. Any help is appreciated, thanks.

kdbanman
  • 10,161
  • 10
  • 46
  • 78
mbrem
  • 91
  • 1
  • 9
  • Have you checked the command path – BhavO Jul 21 '15 at 18:30
  • 2
    Welcome to StackOverflow! Can you include the code of your attempt so far? – kdbanman Jul 21 '15 at 18:32
  • 1
    But you can read their command line: http://stackoverflow.com/questions/504208/how-to-read-command-line-arguments-of-another-process-in-c/504378%23504378 – Tigran Jul 21 '15 at 18:32
  • `I have numerous processes running off of one parent application (they are all started with different executable parameters) so they all have the same process name.` is the parent application your own? Or is it a third-party application? – Matt Burland Jul 21 '15 at 18:33
  • the parent application is a massive third party app. I am currently interning at a company so i am not allowed to post the code. I realize thats hard to work with but i was just wondering if i could differentiate between the processes by checking something other than the name. I will look into checking their command lines, thanks! – mbrem Jul 21 '15 at 18:41

2 Answers2

0

As suggested here, you can query the command-line parameters of a process with WMI, by doing the following, for example if you have the ProcessId:

var wmiQuery = string.Format("select CommandLine from Win32_Process where ProcessId='{0}'", processId);
var searcher = new ManagementObjectSearcher(wmiQuery);
var retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
    Console.WriteLine("[{0}]", retObject["CommandLine"]);

You can probably use a similar query to Win32_Process to find all the ProcessId with the same ProcessName.

Community
  • 1
  • 1
thepirat000
  • 12,362
  • 4
  • 46
  • 72
-1

Try by doing below to find all process in a local machine.

Process[] localAll = Process.GetProcesses();

https://msdn.microsoft.com/en-us/library/1f3ys1f9(v=VS.110).aspx

Abin
  • 2,868
  • 1
  • 23
  • 59