Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirsbo/9c3f66cce32b773274f1 to your computer and use it in GitHub Desktop.
Save kirsbo/9c3f66cce32b773274f1 to your computer and use it in GitHub Desktop.
Getting description from a process in VB.NET

Authored in 2010

The process object contains a lot of different information about the process in question, however it lacks the "description" of a process.

To see the description of a given process, hit CTRL+ALT+Delete and start the task manager. From there navigate to "Processes" and look under the "Description" column on the far right. This description is typically the easiest way to identify an application. You would think the process name would be the most obvious choice to identify an application, but this name is not always obvious.

For example, the Visual Studio 2010 process is called "devenv". Not very telling. The description of the process on the other hand is much more usable: "Microsoft Visual Studio 2010". That one doesn't leave much to the imagination, and typically this is what you are after if you are trying to identify an application based on a process.

As mentioned the process object lacks the description of a process. This is because the description is actually not stored in the process, but rather in the file itself. Getting the description is rather simple, but as mentioned, we cannot get it directly from the process object. Instead we have to use a FileVersionInfo object which resides in the System.Diagnostics namespace.

Private Sub WriteProcessDescription()
dim processDescription as string
Dim objProcess=GetProcessFromSomewhere() 'You will have to replace the mock "GetProcessFromSomewhere" function, with a reference to a process or to a method which returns a process reference.

Dim processFileVersionInfo As System.Diagnostics.FileVersionInfo = FileVersionInfo.GetVersionInfo(objProcess.MainModule.FileName)

processDescription = processFileVersionInfo.FileDescription

Debug.Write("The process description is: " & processDescription)
End Sub

In the above code we first need a process object, for the process we wish to know the description of. For getting the process object for the currently active application, read the previous article (link in the top of this post).

Once we have the process object, we create a FileVersionInfo object based off the process' Filename property (objProcess.Mainmodule.Filename). We then simply extract the description from the FileDescription attribute of the FileVersionInfo object to a variable, and write the content of that variable to the immediate window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment