Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

Sometime we need to find out details of running process which is external to your current process, might be a third party one. If you are currently looking for some code to find out details of a process, this post will definitely help you. Here we will learn, how to get the process description using C#.

 

Continue reading to learn about it. Also, sample code has been shared for you to understand it better. If you have specific query, drop a line in the comment section.

 

How to get the Process Description of an external process using C#? (www.kunal-chowdhury.com)

 

If you open the Task Manager in your Windows system and navigate to the details tab, as shown below, you will find out the various process names running in your system. This includes the name of the process, the process ID (aka. PID), status of the process and the description.

 

If you are a developer and looking for an way to retrieve using C#, the “Process” instance doesn’t return this information. To do this, we need to iterate thru the Win32_Process using the ManagementObjectSearcher.

 

Windows Process Information in Task Manager (www.kunal-chowdhury.com)

 

 

Normal SQL like query “Select * from Win32_Process” returns you all the process currently running in the system. You first need to create an object of ManagementObjectSearcher passing the query and then call the Get() method to retrieve all the process. Each process consists of different properties which returns the value of it. For example, “Name” and “ExecutablePath” returns the name and path of the process.

 

Once you have the path of the process executable, you can use FileVersionInfo.GetVersionInfo(…) method to retrieve the file description. Below is the code snippet, which will give you clear understanding:

public static void GetProcessInformations()
{
    var searcher = new ManagementObjectSearcher("Select * From Win32_Process");
    var processList = searcher.Get();

    foreach (var process in processList)
    {
        var processName = process["Name"];
        var processPath = process["ExecutablePath"];

        if (processPath != null)
        {
            var fileVersionInfo = FileVersionInfo.GetVersionInfo(processPath.ToString());
            var processDescription = fileVersionInfo.FileDescription;

            Console.WriteLine("{0} - {1}", processName, processDescription);
        }
    }
}

 

Windows Process Information (www.kunal-chowdhury.com)

 

If you run the above code snippet, this will result the above output in console screen. I hope the post was simple and easy to understand. If you have any queries on this front, do let me know. I will try to revert you as soon as possible.

 

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.