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
LVL 1
deshawAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.