Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > VB6 > Как узнать ID другого процесса?


Автор: GreatReaper 14.3.2006, 16:48
Допустим, открыт стандартный Блокнот (notepad.exe). Каким образом можно получить ID процесса "notepad.exe" ?

Автор: Romikgy 14.3.2006, 17:34
FindWindow - находишь блакнот
GetWindowThreadProcessId - узнаешь пид по хенделу окна

Автор: Voldemar2004 14.3.2006, 18:47
Код
Option Explicit

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParrent As Long, ByValhWndChildren As Long, ByVal lpClassName As String, ByVal lpWindowName As String)

Dim hw As Long

Private Declare Function GetWindowThreadProcessId _
Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

                    
Private Sub Command1_Click()

Dim sCaption As String

sCaption = "Безымянный - Блокнот"

hw = FindWindow(vbNullString, sCaption)

Dim pID As Long

MsgBox "Хэндл = " & hw
MsgBox "pID = " & GetWindowThreadProcessId(hw, pID)

End Sub


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)