• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1674
  • Last Modified:

C/C++ : How to find the idle time for local windows machine

Hi,

Could anyone please tell me how could I find the my machine's idle time using C/C++? Basically I am building client-server application where I will need to prompt server side user if his/her machine is not idle for 5 minutes. so when connection request received on my Server service, it should first check whether machine is idle for 5 minutes and if not then only it will prompt the dialog else not.

Thanks,
Paresh
0
deshaw
Asked:
deshaw
  • 2
  • 2
1 Solution
 
jkrCommented:
You can call 'GetLastInputInfo()' (http://msdn.microsoft.com/en-us/library/ms646302(VS.85).aspx) to accomplish this. See e.g. http://www.codeproject.com/KB/system/rtwidledll.aspx ("RtwIdleDll Control - DLL to track the system idle time"). The scoop would be to
//returns the time from system startup to last input in milliseconds
 
DWORD RtwIdleDll::RtwIdleDllControl::GetLastInputTime(void)
{
    LASTINPUTINFO lastInput;
    lastInput.cbSize = sizeof(LASTINPUTINFO);
 
    BOOL success = GetLastInputInfo(&lastInput);
 
    if(!success)
    {
        DWORD err=GetLastError();
        // report error, throw exception, etc
 
    }
 
    DWORD lastInputTime = lastInput.dwTime;
    return lastInputTime;
}

Open in new window

0
 
SreejithGCommented:
the source code you are looking for is avilable in
http://read.pudn.com/downloads/sourcecode/windows/system/1439/LOGGEDON.C__.htm
0
 
SreejithGCommented:
sorry wrong url for this question
0
 
deshawAuthor Commented:
jrk, The code is not working properly. It seems the output is not in milliseconds.
0
 
deshawAuthor Commented:
While researching on GetLastInputInfo, I found that it returns session wise idle time and not system wide. Could you tell me how to get system wide idle time.

Icreased the points for this.

from http://msdn.microsoft.com/en-us/library/ms646302(VS.85).aspx
"This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function."

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now