dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] How to detect an application

  1. #1
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    [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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,224

    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.

  3. #3
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    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.

  4. #4
    Join Date
    Mar 2006
    Posts
    12

    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

  5. #5
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    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?

  6. #6
    Join Date
    Nov 2008
    Posts
    3

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)