How to check programatically , either a program is running or not.

Posted on 2004-11-03
Last Modified: 2010-04-01
Like in Task Manager, we can see a program runnnning or not, is there any way that we can check programaticallly , either the program is running or not.
Can we check from registry etc or from task manager.
Please tell me how.
i would be grateful
Question by:ifzah
    LVL 39

    Expert Comment

    The EnumProcesses function retrieves the process identifier for each process object in the system. You could call OpenProcess with PROCESS_QUERY_INFORMATION flag to get a HMODULE handle of each process. The handle could be used for GetModuleFileName that gives the filepath of the executable.

    Regards, Alex

    LVL 12

    Accepted Solution

    LVL 22

    Expert Comment

    You can get a list of process names, but if a process doesnt want to be found, there are lots of ways it can hide.
    LVL 2

    Expert Comment

    Try this.

    HMODULE hModules[10];
    TCHAR szFileName[MAX_PATH];


    EnumProcessModules(process, hModules, sizeof(hModules), &nModuleNo);

    DWORD nModuleNo /= sizeof(hModules[0]);

    if ( GetModuleFileNameEx(process, hModules[0], szFileName, sizeof(szFileName)) )
            // EXE name will be got in szFileName
    LVL 22

    Expert Comment

    >  // EXE name will be got in szFileName

    Note that IIRC there's nothing secure in the exe file name, it's not checksummed or MD5'ed or digitally signed or anything, so any program or spyware or virus or worm is free to change the name to anything at any instant.

    You might have better luck checking the executable's current data segment for strings it HAS to have in it, like "/bin/sh" or in Windows some likely path or file name it works with.

    Or even better, if you're looking for some nasty program, look in its code for calls or loaded images of the core system DLL's.

    LVL 86

    Expert Comment

    >> Like in Task Manager

    See ("How To Enumerate Applications Using Win32 APIs")

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now