enumerate all processes of the system, if "explorer.exe" is found, you can consider user login.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;
呵呵,这个问题,看来连大名鼎鼎的masterz()也不知道:)是这样的: 当用户登录时,Internet Explorer在启动任务条时,将向系统所有顶层窗口广播一个TaskbarCreated消息,而注销时,会有一个WM_QUERYENDSESSION消息。详细信息,可以在MSDN中搜索“WM_TASKBARCREATED”关键字,可查到1999年Microsoft Systems Journal的一篇Q&A,其中有实现的代码。
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");
}