This my current script I have to logoff a user on a terminal as soon as they exit a certain program.
This works just fine because the computer ends all processes and logs off. However, I now want to run another process when a certain process ends. Because of the Do Loop, infinite processes are started...i.e.
spawns "infinite" instances of Calculator. I'm not good with Do, Loop, and Until, so any help would be appreciated.
Code:
Set WshShell = WScript.CreateObject ("WScript.Shell")
strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
WScript.Sleep(15000)
Do
Set colProcessList = objWMI.ExecQuery _
("Select * from Win32_Process Where Name = 'app.exe'")
If colProcessList.Count = 0 Then
wshShell.Run "c:\windows\system32\logoff.exe"
End If
Loop
Code:
Set WshShell = WScript.CreateObject ("WScript.Shell")
strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
WScript.Sleep(15000)
Do
Set colProcessList = objWMI.ExecQuery _
("Select * from Win32_Process Where Name = 'app.exe'")
If colProcessList.Count = 0 Then
wshShell.Run "c:\windows\system32\calc.exe"
End If
Loop