Question:
Using VB6 to find the PID of a process?
2006-12-03 04:05:42 UTC
Say I have a process running in the background eg
c:\windows\hello.exe

I have code which will terminate that process given the Process ID or the form windows handle. I can find out the PID by using a 3rd party process manager but how can I find it out by using code?
Three answers:
Jim R
2006-12-03 06:17:49 UTC
Here is the code required:



Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lparam As Long) As Long



Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long



Global wwnd As Long





Public Sub CaptureWindow()

Call EnumWindows(AddressOf EnumWindowProc, 1)

End Sub



Public Function EnumWindowProc(ByVal hwnd As Long, _

ByVal lparam As Long) As Boolean

Dim sTitle As String

sTitle = Space(50)



Call GetWindowText(hwnd, sTitle, Len(sTitle))



If InStr(sTitle, "Hello") <> 0 Then 'Check for what ever is in the form title bar

EnumWindowProc = False

wwnd = hwnd

Else

EnumWindowProc = True

End If

End Function
Bassem
2006-12-03 12:10:45 UTC
I can't give you the code but i can give you a hint on how you can do it:



In vb6 you can type the command and then redirect it's results to a txt file then you can extract these results in vb and use the ID of the process.



i'm not sure but you can use this: tasklist > C:\tasks.txt

for example and you'll get the results in your tasks.txt file then you can use that file to extracts IDs you want in VB



good luck
Mihai L
2006-12-03 14:07:31 UTC
Take a look here:

http://support.microsoft.com/kb/187913


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...