-
Jun 22nd, 2008, 06:01 PM
#1
Thread Starter
Member
-
Jun 22nd, 2008, 07:43 PM
#2
Re: [ReQ Help] Get Handle from PID Please HELP
Not sure know what you mean by renaming a handle but you might want to take a look at the zip file in this thread as it has some code that might help.
-
Jun 23rd, 2008, 06:43 AM
#3
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
no it dousnt help ok i try to explain it again (my english isn't verry good)
at the task maneger in the process area the game is called "sro_client.exe"
but at the taskbar the window normal called "sro_client" is renamed to difrent stuff like Troy - Cha0sBG and stuff i need a way to detect what it's called at the taskbar window
-
Jun 23rd, 2008, 08:58 AM
#4
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
so can anyone help with this ?
-
Jun 23rd, 2008, 11:51 AM
#5
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
first i whoud like to say sry for the spam
second i found something but dousnt work ... related to my question
vb Code:
strQuery = "select * from Win32_Process"
strMoniker = "winmgmts:\\" & Trim(strComputerName)
Set refWMI = GetObject(strMoniker)
Set colProcesses = refWMI.ExecQuery(strQuery)
If colProcesses.count = 0 Then
Else
For Each refProcess In colProcesses
If refProcess.Terminate() = 0 Then
Debug.Print "(PID " & refProcess.Handle & ") " _
& refProcess.Name & " Terminated on - " _
& strComputerName
Else
Debug.Print "Unable to terminate - " _
& refProcess.Name & " on " _
& strComputerName & Chr(13)
End If
Next
End If
End Sub
can someone help with it ? ty.
i like it to search the process for process called "sro_client.exe" and give the name of the handle on the taskbar of that process.
-
Jun 23rd, 2008, 12:43 PM
#6
Re: [ReQ Help] Get Handle from PID Please HELP
That isn't renaming the handle, which you can't do anyway that I know of, it is changing the text in the window caption. Have a look at this thread for an example of how to get the caption of an external window.
-
Jun 23rd, 2008, 01:06 PM
#7
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
well i wanna get the handle name of a window on the taksbar from it's Process ID
-
Jun 23rd, 2008, 01:32 PM
#8
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
vb Code:
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
Dim i As Long
Dim j As Long
i = GetForegroundWindow
If ReturnParent Then
Do While i <> 0
j = i
i = GetParent(i)
Loop
i = j
End If
GetActiveWindowTitle = GetWindowTitle(i)
End Function
Private Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)
GetWindowText hwnd, s, l + 1
GetWindowTitle = Left$(s, l)
End Function
ok there is the code but how do i make this code to search for process "sro_client.exe" and return the handle of the active window in the task bar ?
-
Jun 23rd, 2008, 02:22 PM
#9
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
Cuz There Where it says "Mercury - LiGh7St0rM" Everytime is difrent name
-
Jun 23rd, 2008, 05:14 PM
#10
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
come on even after my pic explain noone is able to understand ?
-
Jun 23rd, 2008, 05:48 PM
#11
Re: [ReQ Help] Get Handle from PID Please HELP
Originally Posted by Cha0sBG
no it dousnt help ok i try to explain it again (my english isn't verry good)
at the task maneger in the process area the game is called "sro_client.exe"
but at the taskbar the window normal called "sro_client" is renamed to difrent stuff like Troy - Cha0sBG and stuff i need a way to detect what it's called at the taskbar window
I would assum the taskbar text for a program would be the same as it's titlebar text which my example should return when you pass it sro_client.exe, but I guess it's not the same thing. Sorry couldn't help, good luck!
-
Jun 23rd, 2008, 06:08 PM
#12
Thread Starter
Member
Re: [ReQ Help] Get Handle from PID Please HELP
ahh i just want to get the name of the window on the taskbar cuz most time it's renamed ;(
-
Jun 23rd, 2008, 07:28 PM
#13
Hyperactive Member
Re: [ReQ Help] Get Handle from PID Please HELP
when you look on an API spy, is the Classname of the game window always the same? you can do a fast,easy, search using that if it is(it usually always is, but they can change it to whatever they like when creating it if they desire).
from all the API i've encountered i've found ways to retrieve the exe name if i know the handle, but never the handle of the window if you know the exe name. The problem with it is that there can be alot of windows associated with an exe file so pointing to one specific window isn't easy. i was going to tell you how to do it but i figured i'd just write it myself i took this from tidbits of code i have laying around and changed it to fit my needs. hopefully this works successfully for you.
Code:
Option Explicit
Private Const MAX_PATH As Long = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Const TH32CS_SNAPPROCESS As Long = 2&
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
Dim MyExe As String
Dim myProcessID As Long
Dim MyHandle As Long
MyExe = "MyExeProgram.exe" 'case sensitive unless you wanna easily change it
myProcessID = FindProcessID(MyExe)
MyHandle = FindtheWindow(myProcessID)
Me.Caption = "Window Handle = " & MyHandle
End Sub
Private Function FindProcessID(ByVal pExename As String) As Long
Dim ProcessID As Long, hSnapShot As Long
Dim uProcess As PROCESSENTRY32, rProcessFound As Long
Dim Pos As Integer, szExename As String
' Create snapshot of current processes
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
' Check if snapshot is valid
If hSnapShot = -1 Then
Exit Function
End If
'Initialize uProcess with correct size
uProcess.dwSize = Len(uProcess)
'Start looping through processes
rProcessFound = ProcessFirst(hSnapShot, uProcess)
Do While rProcessFound
Pos = InStr(1, uProcess.szExeFile, vbNullChar)
If Pos Then
szExename = Left$(uProcess.szExeFile, Pos - 1)
End If
If szExename = pExename Then
'Found it
ProcessID = uProcess.th32ProcessID
Exit Do
Else
'Wrong, so continue looping
rProcessFound = ProcessNext(hSnapShot, uProcess)
End If
Loop
CloseHandle hSnapShot
FindProcessID = ProcessID
End Function
Private Function FindtheWindow(ByVal ProcessID As Long) As Long
Dim cHandle As Long
Dim RetHwnd As Long
Dim myProcessID As Long
cHandle = GetDesktopWindow()
RetHwnd = GetWindow(cHandle, GW_CHILD)
Do While RetHwnd
If IsWindowVisible(RetHwnd) Then
Call GetWindowThreadProcessId(RetHwnd, myProcessID)
If myProcessID = ProcessID Then
Exit Do
End If
End If
RetHwnd = GetWindow(RetHwnd, GW_HWNDNEXT)
Loop
FindtheWindow = RetHwnd
End Function
-
Jun 23rd, 2008, 08:10 PM
#14
Hyperactive Member
Re: [ReQ Help] Get Handle from PID Please HELP
well i was looking at your question and seen i had forgotten to tell you how to get the caption from the Handle, i only got the handle to it..
just add this to the code i provided above in the appropriate locations.
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Const WM_GETTEXT As Long = &HD
Private Const WM_GETTEXTLENGTH As Long = &HE
Private Function GetText(ByVal WindowHandle As Long) As String
'gets the text of a textbox or a caption of most controls
Dim Buffer As String
Dim TextLength As Long
TextLength = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0&, 0&)
Buffer = String$(TextLength, 0&)
SendMessage WindowHandle, WM_GETTEXT, TextLength + 1, Buffer
GetText = Buffer
End Function
Private Sub Form_Load()
Me.Caption = GetText(MyHandle)
End Sub
-
Mar 13th, 2021, 07:55 AM
#15
New Member
Re: [ReQ Help] Get Handle from PID Please HELP
Hi Billy,
Thank you for sharing this and for your efforts.
I am about to use this code for my commercial application.
Can I use it Billy ? With your kind permission ?
Kind Regards,
Veera Raghavan
+91 9371074189
-
Mar 13th, 2021, 09:26 PM
#16
Re: [ReQ Help] Get Handle from PID Please HELP
Considering that they posted this 13 years ago, I would say that they won't even see your request. If you use it, just add a comment mentioning who you got it from, and where.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|