How do I make this script run 5 times and then end.

I have tried putting in a Do script but haven't been able to make it run 5 times and then quit. Can somebody help me with it....


On Error Resume Next

' EXCEPTION PROGRAM TERMINATION
Dim arrExceptions(1)
Set fso = CreateObject("scripting.FileSystemObject")
Set wshnetwork = CreateObject("wscript.network")
On Error Resume Next


arrExceptions(0)="EXCEPTED CPU"

exception=False
For each name in arrExceptions
     If ucase(wshNetwork.Computername) = ucase(name) Then
          WScript.Quit(0)
          exception=True
     Else
     End If
next

If exception Then
Else
     Call KillProcess(wshnetwork.computername)
'     Call ListSoftware(wshnetwork.computername)
End If


Function KillProcess(strComputer)
dim arrProcessList(4)
arrProcessList(0) = "TSWebSvc.exe"
arrProcessList(1) = "Worun32.exe"
arrProcessList(2) = "Worun32.exe"
arrProcessList(3) = "Worun32.exe"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")


For Each objProcess In colProcesses
     For Each strBadProcess In arrProcessList
          If ucase(objProcess.name)=ucase(strBadProcess) Then
               term=objprocess.terminate()
               If term=0 Then
' "Terminated Process " 
               Else  
' " Found and NOT terminated"  

               End If      
          Else      
          End If
     Next
Next
End Function  

wscript.sleep 1000

WScript.Quit(0)
LVL 1
LutherB40Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
2AngelConnect With a Mentor Commented:
but it is running 5 times - the loop is supposed to be on your main code an the function is supposed to be out of the loop (you are calling the function and the the code continue to the next line after function calling).
You can check it by putting a msgbox like this:

for x = 1 to 5
msgbox x
On Error Resume Next

' EXCEPTION PROGRAM TERMINATION
Dim arrExceptions(1)
Set fso = CreateObject("scripting.FileSystemObject")
Set wshnetwork = CreateObject("wscript.network")
On Error Resume Next


arrExceptions(0)="EXCEPTED CPU"

exception=False
For each name in arrExceptions
     If ucase(wshNetwork.Computername) = ucase(name) Then
          WScript.Quit(0)
          exception=True
     Else
     End If
next

If exception Then
Else
     Call KillProcess(wshnetwork.computername)
'     Call ListSoftware(wshnetwork.computername)
End If

next

Function KillProcess(strComputer)
dim arrProcessList(4)
arrProcessList(0) = "TSWebSvc.exe"
arrProcessList(1) = "Worun32.exe"
arrProcessList(2) = "Worun32.exe"
arrProcessList(3) = "Worun32.exe"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")


For Each objProcess In colProcesses
     For Each strBadProcess In arrProcessList
          If ucase(objProcess.name)=ucase(strBadProcess) Then
               term=objprocess.terminate()
               If term=0 Then
' "Terminated Process " 
               Else  
' " Found and NOT terminated"  

               End If      
          Else      
          End If
     Next
Next
End Function  

wscript.sleep 1000

WScript.Quit(0)
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(Potentially stupid answer)

Dim x

For x = 1 to 5
  'Your code goes here.
Next
End
0
 
LutherB40Author Commented:
It didn't like that. gave me a line error (syntax error) in line 33... Char 1


Function KillProcess(strComputer)
dim arrProcessList(4)

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
2AngelCommented:
the answer above is missing the: x = x +1
0
 
2AngelCommented:
oooppppssss it was OK i'm sorry.

the problem is that the Next needs to be before the "Function KillProcess(strComputer)" becuase you gon'a run your MainProgram 5 times...
0
 
LutherB40Author Commented:
I want the whole thing to run 5 times and quite though, not just part of it.
0
 
2AngelCommented:
bytheway, you can simulate what i'm saying by this code:

for x = 1 to 5

msgbox x & " Main"

if x = 3 then call a

next

msgbox x & " Main after Fucntion"

Function a

      msgbox x & " Function"

End Function
0
All Courses

From novice to tech pro — start learning today.