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.
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.
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:
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.