Solved

Tracking system idle time

Posted on 2004-03-26
4
305 Views
Last Modified: 2010-04-15
I am creating a component that has to do windows screen lock based on the system idle time.
Say if the system is idle for 15 mins it should lock the screen. How can I track the system idle time ?
Is there any readymade utility for this ?


Regards
Renjith
0
Comment
Question by:renjith
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
Comment Utility
Use GetLastInputInfo API.

The GetLastInputInfo function retrieves the time of the last input event.

BOOL GetLastInputInfo(
  PLASTINPUTINFO plii   // last input event
);

plii
[out] Pointer to a LASTINPUTINFO structure that receives the time of the last input event.

typedef struct tagLASTINPUTINFO {
  UINT cbSize;
  DWORD dwTime;
};

See also: GetTickCount API.
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
Take a look at this code:

using System;
using System.Runtime.InteropServices;

namespace Test1
{
    class Class1
    {
        [StructLayout(LayoutKind.Sequential)]
        struct LASTINPUTINFO
        {
            public int cbSize;
            public int dwTime;
        }

        [DllImport ("User32.dll")]
        static extern void GetLastInputInfo(ref LASTINPUTINFO info);

        [DllImport ("Kernel32.dll")]
        public static extern int GetTickCount();

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            LASTINPUTINFO info = new LASTINPUTINFO();
            info.cbSize = Marshal.SizeOf(info);

            GetLastInputInfo(ref info);
            int n = GetTickCount();

            int nIdle = n - info.dwTime;

            Console.WriteLine("Idele time (ms): {0}", nIdle);
        }
    }
}
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now