-
November 26th, 2008, 12:43 PM
#1
[RESOLVED] How to detect an application
Hi Folks,
I was wondering about the different ways to find/detect a running application or a process.
Afaik, if you know the window class and/or title of an application you can easily use FindWindow(), FindWindowEx.
I guess this also works if the target window has a SW_HIDE flag (what not always was the case).
Lets rule that out, what other options do you have in code?
You could use EnumProcesses(), open each Process and do some search. But can you surely detect an specified application that way?
Are there other options to accomplish this with the win32 api?
I'm creating a little cheating application for several games, and I'm wondering If I always have to do an update if an target application just changes the window title for instance.
Best Regards,
Andy
-
November 27th, 2008, 04:16 PM
#2
Re: How to detect an application
You determine if an application is running by enumerating the processes.
While I could post the code, I'm less inclined to do so given your statement:
I'm creating a little cheating application for several games
I guess maybe I just don't get the whole 'cheating' thing.
-
November 27th, 2008, 06:22 PM
#3
Re: How to detect an application
haha :>
Well I'm cheating on games like tetris and gradius. Fooling around with win32 and data/memory managment.
-
November 28th, 2008, 12:20 AM
#4
Re: How to detect an application
If its your application and you want to check if someone its being run or not. Or you want a single instance of that application.
Create a mutex with a unique name using GUID. At the start of application check if the mutex exist or try to open it. if it succeeds then it means your application is already running. If it fails create the mutex with that name and start the process.
Kavitesh Singh
-
November 28th, 2008, 02:51 AM
#5
Re: How to detect an application
Thanks for answering, but thats not what I need.
I need to detect another application or process, so the question is still open:
What is the most reliable method of detecting an application?
-
November 28th, 2008, 07:00 PM
#6
Re: How to detect an application
Here's a way to find a running exe file. Of course, they could change the exe name just as they could change the window title.
Code:
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
void die (char *msg)
{
fprintf (stderr, msg);
exit (1);
}
DWORD find_running_exe (char *exe_name)
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
hProcessSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
die ("CreateToolhelp32Snapshot");
pe32.dwSize = sizeof (PROCESSENTRY32);
if (!Process32First (hProcessSnap, &pe32))
{
CloseHandle (hProcessSnap);
die ("Process32First");
}
do
{
if (!strcmp (pe32.szExeFile, exe_name))
{
CloseHandle (hProcessSnap);
return pe32.th32ProcessID;
}
} while (Process32Next (hProcessSnap, &pe32));
CloseHandle (hProcessSnap);
return 0;
}
int main (void)
{
DWORD proc;
proc = find_running_exe ("iexplore.exe");
printf ("%u\n", proc);
}
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
|