1. Get a snapshot of the current system using either CreateToolhelp32Snapshot , Process32First and Process32Next incase of 95, or EnumProcesses in case of NT and getting the exe file name from each of them and checking for the relevant name. 2. If you know the Window class name and the title of the window created, using the FindWindow () API.
用CreateToolhelp32Snapshot 如何取得get the exe file name ? 能详细介绍一下吗,我用的系统是win2000。
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;
CreateToolhelp32Snapshot , Process32First and Process32Next incase of 95,
or EnumProcesses in case of NT and getting the exe file name from each of
them and checking for the relevant name.
2. If you know the Window class name and the title of the window created,
using the FindWindow () API.
能详细介绍一下吗,我用的系统是win2000。
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");
}
error C2065: 'EnumProcesses' : undeclared identifier
error C2065: 'EnumProcessModules' : undeclared identifier
error C2065: 'GetModuleFileNameEx' : undeclared identifier
编译错误。还请指教
No such file or directory
我加了,但是出现这样的错误
you can't use it in win98!
fatal error C1083: Cannot open include file: 'psapi.h':
No such file or directory
i build it successfully just now.
我试过了.
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]);改为
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,false,buf[i]);
error C2065: 'EnumProcessModules' : undeclared identifier
error C2065: 'GetModuleFileNameEx' : undeclared identifier