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

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Try this.

HMODULE hModules[10];


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
>  // 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.

>> Like in Task Manager

See ("How To Enumerate Applications Using Win32 APIs")
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.