We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

LutherB40
LutherB40 asked
on
Medium Priority
314 Views
Last Modified: 2010-05-01
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)
Comment
Watch Question

Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
(Potentially stupid answer)

Dim x

For x = 1 to 5
  'Your code goes here.
Next
End

Author

Commented:
It didn't like that. gave me a line error (syntax error) in line 33... Char 1


Function KillProcess(strComputer)
dim arrProcessList(4)

Commented:
the answer above is missing the: x = x +1

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

Author

Commented:
I want the whole thing to run 5 times and quite though, not just part of it.
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)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.