如何从进程名称中获取应用程序名称?
How to get Application name from process name?
当我有进程名称时,我需要知道如何获取这样的应用程序名称:
目前我的进度:
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 returns "explorer",我快到了。我怎样才能得到值"Windows Explorer"?
感谢任何帮助。
由于 Hans 尚未发布答案,这里是他在问题评论中建议的答案。希望大家不要介意我冒昧的写了个回答
Sub GetProcInfo()
Dim activeProcess As Process = GetActiveAppProcess()
With activeProcess
ApplicationName = .MainModule.FileVersionInfo.FileDescription
ProcessName = .ProcessName
WindowTitle = .MainWindowTitle
End With
End Sub
当我有进程名称时,我需要知道如何获取这样的应用程序名称:
目前我的进度:
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 returns "explorer",我快到了。我怎样才能得到值"Windows Explorer"? 感谢任何帮助。
由于 Hans 尚未发布答案,这里是他在问题评论中建议的答案。希望大家不要介意我冒昧的写了个回答
Sub GetProcInfo()
Dim activeProcess As Process = GetActiveAppProcess()
With activeProcess
ApplicationName = .MainModule.FileVersionInfo.FileDescription
ProcessName = .ProcessName
WindowTitle = .MainWindowTitle
End With
End Sub