Link to home
Start Free TrialLog in
Avatar of cnrlzen
cnrlzen

asked on

Inactive window process termination script for Windows 2000/XP

We have a network-based application that has a limited number of licenses. Unfortunately, the vendor has no usage management ability within their licensing system, so users can open the application at 8:00 AM on a Monday and leave it "running" in the background for days at a time and thus needlessly consume a limited license. Management has asked us for a system to kick out users who are inactive. We need to create a Windows script that can be started when the system starts (likely as a service) that will monitor for the name of the process and whether it has been inactive (i.e. a minimized or background window) for an hour or more. The script, running on Windows 2000 Pro and XP Pro, would be required to check for this process every ten minutes. If it finds that the window has been inactive for over one hour, it would terminate the process. The following script is from the Microsoft site and we think it would provide the simple basis for this script (using Notepad.exe as an example):


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")

For Each objProcess in colProcessList
    objProcess.Terminate()
Next


Any assistance would be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of rettiseert
rettiseert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rettiseert
rettiseert

(you also need to MinutesToWait = 60 or any value you want to wait until closing inactive window)
Avatar of cnrlzen

ASKER

Thanks for the suggestion . We would prefer a solution that does not require us to deploy a third-party library that, although free, has no guarantee of being supported in the future. A purely VB script would be preferable.
No dependency files is always better, of course, but since you are working with other processes I think that in some point you will need more power than a script file can give you.

AutoIt is an excelente library, and even if it is not supported in the future, you already have what you want (and more) with its current version. It is a very stable library and I think its even more supported than winmgmts (I find very little information for winmgmts, but autoit has an excelent help file).

Also, autoit its a great help if you want to write other kind of scripts. It has dozens of useful functions, and you anly need to distribute a single dll, and if you dont want that, then you can compile an autoit script into an exe and you will be distributing only that exe.

Avatar of cnrlzen

ASKER

We have something that appears workable but, as often is the case, the original project requirements have broadened and we may have to do this for a number of apps. Is it possible to modify the script to read a text file for a list of the applications (i.e. WindowTitle) to be monitored and closed when inactive? Each app may have its own time limit for each activity. Lastly, would there be a way to add an entry to the Application Event Log EVERY time the script closes an application? I've tried the following (again, from Microsoft) but it only seems to write one entry ever for the application closure:

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    "Payroll application successfully installed."

Thanks a lot for any help.
Thanks for the points, I'm sorry I didn't see your question until now, but anyway, I have to tell you that right now I dont have the time to develop the entire script you need. I recoomend to create many scripts as the one I posted, one for each program you wish to close. you just need to change

WindowTitle = "The title of the window you wanna monitor"

hope this helps