3
我需要知道如何讓應用程序名稱類似這樣的,當我有進程名稱:如何從進程名稱獲取應用程序名稱?
我迄今取得的進展:
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返回「資源管理器」。我怎樣才能得到「Windows資源管理器」的價值? 任何幫助表示讚賞。
使用Process.MainModule.Filename獲取exe的路徑。然後FileVersionInfo.GetVersionInfo(path).FileDescription來獲取描述。 –
太棒了!它工作:)謝謝漢斯! ApplicationName = FileVersionInfo.GetVersionInfo(activeProcess.MainModule.FileName).FileDescription – user3397557
@HansPassant您可以添加答案以解決此問題嗎? –