Problem identifying process "Process []"

0

I have a problem reading and identifying a process, it turns out that they are 3 different processes but they have the same name, the only thing that differs is the PID and the Command line

I am using the following line of code:

Process[] process = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(name));
 if (process.Length == 1)
            {....}

I know you are going to tell me to use the getprocessbyID but I do not want to use the PID since I understand that this can change in the processes.

Do you know any way to review the processes by Command line?

I remain attentive.

    
asked by thiagolope7 08.08.2018 в 21:24
source

3 answers

0

Hello, you can use WMI to consult the processes. In this case you can consult Win32_Process class . I'll give you an example

using System;
using System.Management;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\CIMV2", 
                    "SELECT * FROM Win32_Process"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_Process instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Caption: {0}", queryObj["Caption"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}
    
answered by 08.08.2018 / 22:36
source
0

With TaskList you can see the processes and we will get the table

Even look for someone among this list

tasklist|findstr "chrome.exe"

To stop them

TASKKILL /F /IM excel.exe
    
answered by 09.08.2018 в 17:29
-1

CMD:

for processes:

tasklist

for services:

net start

    
answered by 09.08.2018 в 17:11