find process by filename

Posts 1–4 of 4 · Page 1 of 1
find process by filename
i can find a window with
hw = FindWindow("windowname",NULL);

but how can i find the window name from the .exe filename?
say i wanted to find "game.exe"'s window name, how would i do that?

this is because i use task manager to find the windowname but my program wont pick up the window name from cod4, so maybe if i made it find the window name of iwmp3.exe?

thx in advance for the help.
You need to look up the FindWindow function on msdn, FindWindows first parameter is the class name not window name, so flip them around. If it still doesnt work maybe try EnumWindows.

Heres FindWindow paramaters:
HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
Quote Originally Posted by sgtmattbaker View Post
You need to look up the FindWindow function on msdn, FindWindows first parameter is the class name not window name, so flip them around. If it still doesnt work maybe try EnumWindows.

Heres FindWindow paramaters:
HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
i already know how to use that and it wont work for cod4.
i need a function that will give me the windowname from the filename
Quote Originally Posted by qsc View Post
i already know how to use that and it wont work for cod4.
i need a function that will give me the windowname from the filename
The image name of a process represents it's file name. If you need to locate a process by using the file on the harddrive, That's not possible, as multiple processes can be created with a single executable file. However, if the program is not hidden from the user. You can take a look at the EnumProcesses API to receive all running process's ID. Store them in an array of Unsigned Longs(or DWORD)'s, then use OpenProcess to get a handle each process, pass the handle to GetModuleFileName to get it's file name and filter for Cod.exe or w\e the target is called. If it's the incorrect handle, close it, otherwise, keep it and do whatever you need with it.
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?