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 5977557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:23:17+00:00 2026-05-22T21:23:17+00:00

I use a Windows API call to GetLastInputInfo to determine if the system is

  • 0

I use a Windows API call to GetLastInputInfo to determine if the system is idle. This works in pretty much any scenario – except when Windows is set to bypass the username/password and login automatically.

In this case, querying GetLastInputInfo always returns 0. In normal conditions, it would return the system tick count when the last input occurred.

Does anyone know why? Or does anyone know an alternate method to determine if a windows session is idle?

Edit

This is how the code is written to detect the current system idle time. The detection occurs on a timer and regardless of how long the timer runs, GetLastInputInfo will always return 0 while windows is set to "auto login".

long lastInputTicks = 0;
long idleTicks = 0;

LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
lastInputInfo.dwTime = 0;

if (GetLastInputInfo(ref lastInputInfo)) {
   lastInputTicks = lastInputInfo.dwTime;

   var systemUptime = GetTickCount();

   idleTicks = systemUptime - lastInputTicks;
}

return new TimeSpan(0, 0, (int)(idleTicks / 1000));

Thanks

Update

I’ve confirmed that this only happens because the code runs in a service.

To clarify: Under a normal scenario where auto-login is not being used, the user logs in at the console and the above code — even if running as a service — will return the proper user inactivity time.

However, if auto-login is turned on, then the windows session appears to not run as a typical console session, and is therefore NOT tracked. This applies only when the code is ran from a service and not from the "user space" – it works great in all cases if running from a user space.

That said, I’d really love to find a solution that works from a service in every scenario.

  • 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-22T21:23:17+00:00Added an answer on May 22, 2026 at 9:23 pm

    It returns 0 seconds when GetLastInput() returns FALSE. Which is obviously incorrect. You cannot use code like this in a service, it doesn’t have a way to retrieve user input. If GetLastInput() ever returns FALSE (likely with auto-login) then it will return FALSE forever.

    Having services be aware of user sessions is a lost cause in Windows, a service runs in its own session and doesn’t need a user to be logged-in. Which is the major reason to use a service in the first place. Instead of a program that’s started with, say, a shortcut in the Startup folder. This code might have worked by accident in XP but it definitely won’t work in Vista and Windows 7. Google “session 0 isolation” for more details.

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

Sidebar

Related Questions

Any recommendation of a Fax server to use in Windows? Looking for good API
The windows ESE engine API call JetAttachDatabase have a readonly option. Can I use
When I use the Windows API call GetFileSizeEx() from my Delphi 6 app on
I asked the question Will Rebol 3 extension support any windows api call including
I am trying to use native windows API with Qt using mingw toolset. There
I've found a few tutorials that explain how to use the windows API to
How do I use Windows Vista's FOLDERID API in order to retrieve filepaths for
Can some one specify the windows API, one need to use in order to
Hi i want to use windows form application in way like an api from
In VB6 I'm making a call to the Windows API DnsQuery . Private Declare

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.