如何知道一个应用程序是否运行?
如何在我自己的程序中通过函数判断一个其他的应用程序是否运行,
比如说有一个应用程序xxxx.exe在任务管理器->进程:映象名称中的名字也是
xxxx.exe,我怎么判断它是否已经运行?
推荐阅读
http://www.codeguru.com/system/plist.html
single interface to enumerate processes
//enum process to find a certain module
void cptbview::isapprun(cstring modulename)
{
dword buf[4096];
dword num;
tchar filenamebuf[_max_path+1];
hmodule hmodule;
dword cbreturned;
bool bret=enumprocesses(buf,4095,&num);
bool bfound=false;
cstring msg;
if(!bret)
{
afxmessagebox("error enumprocesses");
return;
}
for(int i=0;i<(int)num;i++)
{
handle hprocess =openprocess(process_query_information¦ process_vm_read,false,buf[i]);
if(hprocess ==null)
continue;
bret=enumprocessmodules(hprocess ,&hmodule, sizeof(hmodule), &cbreturned );
if(bret)
{
dword dwret=getmodulefilenameex(hprocess ,hmodule,filenamebuf,_max_path);
closehandle( hprocess ) ;
if(dwret==0)
{
msg.format("%d",getlasterror());
afxmessagebox(msg);
break;
}
else
{
tchar* pfind=_tcsstr(filenamebuf,modulename);
if(pfind)
{
bfound=true;
break;
}
}
}
}
if(bfound)
afxmessagebox("found it");
else
afxmessagebox("not found");
}
void cptbview::onviewcheckrun()
{
isapprun("notepad.exe");
}


讨论区