• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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
ifzah
0
ifzah
Asked:
ifzah
1 Solution
 
itsmeandnobodyelseCommented:
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

0
 
OnegaZhangCommented:
0
 
grg99Commented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
pb_indiaCommented:
Try this.

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

HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, nProcessID);

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
}
0
 
grg99Commented:
>  // 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.



0
 
jkrCommented:
>> Like in Task Manager

See http://support.microsoft.com/kb/175030/en-us ("How To Enumerate Applications Using Win32 APIs")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now