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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
2AngelCommented:
the answer above is missing the: x = x +1
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.