Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way for a user to launch a Windows application that will only run for a given amount of time, say an hour. After the hour is up, an alert window will pop up, saying "Program will be terminated in five minutes, unless you click here". If the user clicks on the button, the program will run for another hour, after which the alert will pop up again.

If there is no easy way to accomplish this, then I'm willing to have the program simply terminate after a given time, without the pop-up warning.

Ideally, the method should work under both Windows XP and Windows 7.

share|improve this question
    
I believe the most reliable and perhaps simplest way is to write a program to do it. You might be able to achieve the same thing with batch files and schedule task, but it's actually more complicated than programming... –  billc.cn Nov 6 '11 at 14:42
    
@billc.cn: Thanks, but can you provide a little more guidance? Are you referring to a scripting language? In the end, I need some simple way for this to be implemented on workstations, where the end-users can just double-click on an icon to launch the time-limited application. Thanks. –  Alex Chernavsky Nov 6 '11 at 15:47
add comment

2 Answers

You can use AutoIt script for this.

share|improve this answer
    
Thanks, AutoIt looks promising. I was hoping that there would be some easier way to achieve my goal, but it looks like I may have to learn AutoIt. It may come in handy for other uses, though. –  Alex Chernavsky Nov 6 '11 at 15:53
add comment
up vote 1 down vote accepted

I'm answering my own question. Well, actually, the question was answered accurately and completely by user BigBadWolf_000 on Experts Exchange. I'm copying his VBScript code below:

Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet

Set objShell = CreateObject("WScript.Shell")

PromptTime = 60
DelayTime = 5
StrAppPath = "C:\windows\"
AppExec = "notepad.exe"
MsgTxt = "Do you want Notepad to close in 5 minutes?"

objShell.Run chr(34) & StrAppPath & AppExec & chr(34), 1, "False"
Do
    WScript.Sleep (1000 * 60 * PromptTime)
    intAnswer = Msgbox(MsgTxt, vbYesNo, "Please select Yes or No")
    If intAnswer = vbYes Then Exit Do
Loop

WScript.Sleep (1000 * 60 * DelayTime)
Set objWmi = GetObject("winmgmts:") 
Set objQResult = objWmi.Execquery("Select * from Win32_Process where name like '" & AppExec & "'")
For Each objProcess In objQResult 
intRet = objProcess.Terminate(1) 
Next 

Set objShell = Nothing
Set objWmi = Nothing 
Set objQResult = Nothing

Here are the explanatory comments included with BigBadWolf_000's code:

The script below will do the following...
- lauch your application (app must be launched with this script)
- Promt you for action after an hour "Do you want YourApp to close in 5 minutes?" Yes/No
- Yes: Terminates all instances of the app after 5 minutes
- No: Restarts the clock and will prompt you again in an hour

The default PromptTime is set to 60 minutes and the terminate app DelayTime is set to 5 minutes.
You can change number for PromptTime = 60 and DelayTime = 5 to any number in minutes (minimum 1). The default app is set to Notepad so you can test.

Change the path of the app executable...
StrAppPath = "your path goes here, end with  \" 

Change the name of the app executable...
AppExec = "whatever.exe"

Change the popup message txt...withing the quotes
MsgTxt = "Do you want Notepad to close in 5 minutes?"

Copy and paste script to notepad and save as yourfilename.vbs. Double-click on the file to run or create a shortcut to it. Will work with Windows 7 and Windows XP SP3.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.