سؤال

I am trying to write a small program to keep track of user inactivity and after about 30 minutes kill all running adobe reader applications on a Windows 7 computer. The paychex software we use doesn't allow more than one pay stub open at once so if they are not closed and the next employee comes to use the computer they can't view their pay stub.

Maybe this is easier using a batch file or scripting but I know C++ fairly well so that is what I started with.

هل كانت مفيدة؟

المحلول

Detecting that Windows is idle is the hardest part, but luckily you have Windows 7 and can use IIdleTrigger.

After that, it's just a matter of sending a window close message to Adobe Reader. Look for the caption which includes the pay stub name so you close the right instance.

نصائح أخرى

Detecting that Windows is idle is the hardest part

Actually it is very easy. You can use GetLastInputInfo function. This is snippet from a program that I created that does exactly that:

unsigned idle_time;

// get idle time
LASTINPUTINFO last_input_info;
DWORD this_time;

last_input_info.cbSize = sizeof(LASTINPUTINFO);
GetLastInputInfo(&last_input_info);
#pragma warning(suppress: 28159) // Consider using GetTickCount64() instead
this_time = GetTickCount();

idle_time = this_time - last_input_info.dwTime;

Note that this is not event-based. You should put this in a loop and use Sleep to check the idle time from time to time, depending on how often you need. From what you describe, something like every few seconds should be OK.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top