Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1440
  • 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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