VC + + based on Explorer.exe process to detect whether the user has logged in

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.