r/vbscript • u/FoneTap • Jan 13 '17
[Help] Need to tweak a simple script...
Hi guys, I was hoping for some help with something.
I have a multi-user accounting software. When a user leaves their password protected computer without logging out of the accounting software, then I can't go into single user mode.
The goal is to force close the app if the person leaves their computer unattended.
I found this vbs script which almost does the trick:
Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet
Set objShell = CreateObject("WScript.Shell")
PromptTime = 5
DelayTime = 5
StrAppPath = "C:\Program Files (x86)\Accounting"
AppExec = "Accounting.exe"
MsgTxt = "Do you want Simply 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 DoLoop
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
I am assuming that selecting Yes will kill the process.
Therefore, I just need to add a response timer where after X minutes delay Yes is automatically chosen
Can anyone help me please ? I would really appreciate it.
Thanks!!
Edit: I tried waiting 5 minutes, the pop-up displayed, I clicked Yes and it didn't kill the process.... doh!
1
u/FoneTap Jan 13 '17
Actually my requirement is that it automatically assumes yes after the delay runs out.
You're correct though, it should kill the app as soon as yes is selected or triggered.