Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396142
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:22:21+00:00 2026-05-18T04:22:21+00:00

I wanna write a program that should perform some tasks automatically if someone logs

  • 0

I wanna write a program that should perform some tasks automatically if someone logs onto my server.

My questions regarding this are:

  • 1) Is there a last login record that
    is set right after a user logs in
    that I can use/monitor for my
    purpose? If not is there something
    similar I can use?

  • 2) What’s the best way to constantly
    monitor such a value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:22:21+00:00Added an answer on May 18, 2026 at 4:22 am

    Your best (and by far safest) bet is to create a service that accepts the SERVICE_CONTROL_SESSIONCHANGE control.

    This will allow your service control handler to receive a control whenever a user logs on, logs off, locks the session, and various other options. Look for more info in a link blow.

    This is done by creating a service which has the SERVICE_ACCEPT_SESSIONCHANGE flag in the dwControlsAccepted, as following:

    SERVICE_STATUS ss;
    ...
    ss.dwControlsAccepted |= SERVICE_ACCEPT_SESSIONCHANGE;
    

    Followed by:

    // This lets the service accept the session change ctrls
    // The service handle here is received by calling RegisterServiceCtrlHandler
    SetServiceStatus(hServiceHandle,
                     &ss);
    

    This will allow windows to send SERVICE_CONTROL_SESSIONCHANGE controls to your HandlerEx function, which should look something like this:

    DWORD WINAPI HandlerEx(DWORD dwControl,
                           DWORD dwEventType, 
                           LPVOID lpEventData, 
                           LPVOID lpContext)
    {
       switch (dwControl)
       {
        ...// Regular control handling
           case (SERVICE_CONTROL_SESSIONCHANGE):
                switch(dwEventType)
                {
                    case(WTS_SESSION_LOGON):
                        // Handle logon
                    break;
    
                    case(WTS_SESSION_LOCK):
                        // Handle lock
                    break;
                    ...
                }
           break;
    
           ...
       }
    }
    

    You can read up on all the different session change notifications you can receive from here: WM_WTSSESSION_CHANGE, all the notifications you’ll need are in the wParam part of the description.

    Well, that’s the gist of it anyway. You can read more info on the handlerex function here: HandlerEx and more information about services in general here: Service Functions. I suggest you read up on the ServiceMain function, RegisterServiceCtrlHandler function and, most importantly, read the examples posted on the MSDN pages. They’re super helpful.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wanna write a C program that runs on a mobile phone. Just for
i'm trying to write a program that solves the rsa challenge (yes i have
I wanna write a little c++ program using libcurl. It's for a school project
in this i write the cookie value in controller file. i wanna read that
I write a comunication program with c/s mode in C# ,server and client program
I wanna write a simple RSS Feed reader in C++. I understand that the
I wanna write a application with push email capablity. Can some one guide me
I want to write a program that sends GPS location (lattitude, longitude) at a
Wanna write a RegEx to validate a driving license. if it doesn't start with
I wanna add server controls by using javascript. The main purpose of why I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.