5

I need to know how to get application name like this when I have process name:

enter image description here

My progress so far:

Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpdwProcessId As Int32) As Int32 Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As IntPtr 'Private Declare Auto Function GetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer Private makel As String Private Function GetActiveAppProcess() As Process Dim activeProcessID As IntPtr GetWindowThreadProcessId(GetForegroundWindow(), activeProcessID) Return Process.GetProcessById(activeProcessID) End Function Sub GetProcInfo() Dim activeProcess As Process = GetActiveAppProcess() With activeProcess ProcessName = .ProcessName Windowtitle = .MainWindowTitle 'Application name = ? End With End Sub 

I'm almost there except that Process.ProcessName returns "explorer". How can I get the value "Windows Explorer"? Any help is appreciated.

3
  • 4
    Use Process.MainModule.Filename to get the path to the exe. Then FileVersionInfo.GetVersionInfo(path).FileDescription to get the description. Commented Nov 6, 2015 at 10:59
  • Awesome! It worked :) Thanks Hans! ApplicationName = FileVersionInfo.GetVersionInfo(activeProcess.MainModule.FileName).FileDescription Commented Nov 6, 2015 at 13:23
  • @HansPassant can you add the answer to get this question closed? Commented Nov 6, 2015 at 20:35

1 Answer 1

4

Since Hans hasn't posted an answer yet, here's the answer as he suggested in the comments on the question. I hope everyone doesn't mind that I've taken the liberty to go ahead and write an answer.

Sub GetProcInfo() Dim activeProcess As Process = GetActiveAppProcess() With activeProcess ApplicationName = .MainModule.FileVersionInfo.FileDescription ProcessName = .ProcessName WindowTitle = .MainWindowTitle End With End Sub 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.