Here is a VC + + according to the Explorer.exe process to detect whether the user has logged in, I hope the example can help you.
| code is as follows |
&nbs P; |
void CALLBACK Timecall (UINT Timeid, UINT umsg, Dword_ptr Dwuser, D WORD dw1, dword_ptr dw2) { dword Dwsessionid = Wtsgetactiveconsolesessionid (); & nbsp; //Get the console session handle Hsnap = createtoolhelp32snapshot (th32cs_snapprocess, 0); /To create an environment snapshot if (hsnap = = invalid_handle_value) return; //traverses the snapshot, obtains the application name through the snapshot's procentry.szexefile, and obtains the corresponding PID processentry32 procentry; procentry.dwsize = sizeof (PROCESSENTRY32); process32first (Hsnap, &procentry); dword dwexplorerpid =-1; do { if (strcmp (Procentry.szexefile, "explorer.exe") = 0) { & Nbsp; dword dwexplorersessid = 0; &Nbsp;if (Processidtosessionid (Procentry.th32processid, &dwexplorersessid) && Dwexplorersessid = = Dwsessionid) { dwexplorerpid = procentry.th32processid; break; } } } while (Process32Next (Hsnap, &procentry)); log_info ("detect if the user is logged on:%s", (dwexplorerpid = = 1)? "Not logged in": "Already logged in"); if (dwexplorerpid!=-1) { //logged in dosomething (); } }< /p> |