如何从进程名称获取应用程序名称?

时间:2015-11-06 10:28:54

标签: .net vb.net process taskmanager

当我有进程名称时,我需要知道如何获取这样的应用程序名称:

enter image description here

到目前为止我的进展:

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

我几乎在那里,但Process.ProcessName返回“explorer”。如何获取“Windows资源管理器”的值? 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

由于汉斯还没有发布答案,这就是他在问题评论中提出的答案。我希望每个人都不介意我冒昧地继续写下答案。

Sub GetProcInfo()
   Dim activeProcess As Process = GetActiveAppProcess()
   With activeProcess
        ApplicationName = .MainModule.FileVersionInfo.FileDescription
        ProcessName = .ProcessName
        WindowTitle = .MainWindowTitle
   End With
End Sub