views:

60

answers:

1

I have one Windows Service/Application running silently on the PC, when user starts any program , i need to count the time and close it down (program) in 15 Minutes. Even when the user close down the particular program ( say winword.exe) with in 15 min, and reopen it... the program should automatically close on 15 th minute...

+1  A: 

There are two ways I think you may acheive this
1. Manual polling of applications started using EnumProcessModules and terminate them using TerminateProcess and
2. Using Dll injection using App_Init registry

I'll talk a little more about number 2. When you place your dll name in the following registry value in AppInit_DLLs in the following registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows, you can make the dll load with almost every application that launches. You could write a 15 min timer in the dllmain of your injected dll and do exitprocess() when it elapses, eventually taking down the entire process.

Samrat Patil
+1, yet another variation would be to hook CreateProcess api call and then start timer if new process the target process.
VinayC
@VinayC - hooks are to be used with a lot of caution as they tremendously hit the performance and stability of the system. Not recommended! :)
Samrat Patil
Actually the process started by the user, but we need to monitor and check for it and then close...
Rajesh Subramanian
Both the above listed methods would work for processes started by users. For the first method you need admin rights to terminate processes, which, if you're running through a services, will automatically be taken care of.
Samrat Patil
Thanks Samrat..
Rajesh Subramanian