Pause script a couple of times during different phases

Author Message
piet200

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 11/25/2011
  • Status: offline
Pause script a couple of times during different phases Wednesday, November 30, 2011 1:49 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
What am I looking for ?

A script which pings a machine and when the machine replies it has to wait for 5 minutes before executing a task.
After that task I need to execute a few more tasks which all should have a pause of a minute or 2, or even better after the previous task has ended.

How can I execute a couple of tasks with a pause after every task ?

ex.
  • ping machine 10.10.10.20
  • when reply wait 5 minutes
  • execute sub1
  • wait until sub1 is finished
  • execute sub2
  • wait until sub2 is finished
  • execute sub3
  • etc.
HTA script:
<HTML> 
 <HEAD> 
 <TITLE>Autostart Tools</TITLE> 
 <HTA:APPLICATION ID ="oHTA" 
 APPLICATIONNAME = "RunRoutine" 
 BORDER = "Thin" 
 BORDERSTYLE = "Normal" 
 CAPTION = "Yes" 
 ICON = "" 
 INNERBORDER    = "No" 
 MAXIMIZEBUTTON    = "Yes" 
 MINIMIZEBUTTON    = "Yes" 
 NAVIGABLE    = "Yes" 
 SCROLL = "Yes" 
 SCROLLFLAT    = "No" 
 SELECTION    = "Yes" 
 SHOWINTASKBAR = "No" 
 SINGLEINSTANCE = "No" 
 SYSMENU = "Yes" 
 WINDOWSTATE = "normal"  
 > 
 </HEAD> 
 
 <script language="VBscript"> 
 Sub Window_onLoad 
 intWidth = 500 
 intHeight = 400 
 Me.ResizeTo intWidth, intHeight 
 Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2)) 
 'Call ProcessKill 
 Set objShell = CreateObject("WScript.Shell") 
 boolPinged = Ping("10.10.10.20") 
 While boolPinged = False 
 ' Wait for one second, given by -n # 
 objShell.Run "cmd /c ping -n 300 localhost > nul", 0, True 
 boolPinged = Ping("10.10.10.20") 
 Wend 
 Call sub1 
 Call sub2 
 Call sub3 
 Call CloseWindow 
 End Sub 
 
 Function Ping(strComputer) 
 Dim objShell, boolCode 
 Set objShell = CreateObject("WScript.Shell") 
 boolCode = objShell.Run("Ping -n 1 -w 1 " & strComputer, 0, True) 
 If boolCode = 0 Then 
 Ping = True 
 Else 
 Ping = False 
 End If 
 End Function 
 
 Set objWMIService = GetObject("winmgmts:" _ 
 & "{impersonationLevel=impersonate}!\\" _  
 & strComputer & "\root\cimv2")  
 
 Set colProcess = objWMIService.ExecQuery _ 
 ("Select * from Win32_Process Where Name = " & strProcessKill ) 
 For Each objProcess in colProcess 
 objProcess.Terminate() 
 Next  
 
 Sub sub1 
 MsgBox("sub1") 
 End Sub 
 
 Sub sub2 
 MsgBox("sub2") 
 End Sub 
 
 Sub sub3 
 MsgBox("sub2") 
 End Sub 
 
 Sub CloseWindow 
 self.close 
 End Sub 
 
 </script> 
 </HEAD>  
 <body STYLE="font:8 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>         
 <table width='90%' height = '100%' align='center' border='0'> 
 <tr> 
 <td align="center"> 
 <h4>Autostart tools</h5><br> 
 <h5>Please be patient</5><br><br><br> 
 <h2><Font color = FFD700><b><br><br>Do not close this window</b></font></h2> 
 </td> 
 </tr> 
 <tr> 
 <td align='center'> 
 <br><br> 
 <span name="span_text" id="span_text"></span> 
 <br><br> 
 </td> 
 </tr> 
 </table> 
 </body>  
 </HTML>

<message edited by piet200 on Wednesday, November 30, 2011 1:54 AM>
 
#1
    Hackoo

    • Total Posts : 105
    • Scores: 4
    • Reward points : 0
    • Joined: 6/25/2010
    • Status: offline
    Re:Pause script a couple of times during different phases Wednesday, November 30, 2011 4:20 AM (permalink)
    0
    [This post was marked as helpful]
    Hi Try to implement this Function into your HTA and call it as you want, for example if you want to make pause for 10 secondes you call it by this way :
    Call Sleep (10)
     
    Sub Sleep(strSeconds)
    Dim strCmd
    Set objShell=CreateObject("wscript.shell")
    strCmd = "%COMSPEC% /c ping -n " & strSeconds & " 127.0.0.1>nul"
    objShell.Run strCmd,0,1
    End Sub
     
     
     
    #2
      59cobalt

      • Total Posts : 979
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:Pause script a couple of times during different phases Wednesday, November 30, 2011 7:15 AM (permalink)
      0
      Hackoo
      Sub Sleep(intSeconds)
      Dim strCmd
      Set objShell=CreateObject("wscript.shell")
      strCmd = "%COMSPEC% /c ping -n " & intSeconds + 1 & " 127.0.0.1>nul"
      objShell.Run strCmd,0,1
      End Sub
      Fixed.
       
      #3
        piet200

        • Total Posts : 4
        • Scores: 0
        • Reward points : 0
        • Joined: 11/25/2011
        • Status: offline
        Re:Pause script a couple of times during different phases Wednesday, November 30, 2011 6:46 PM (permalink)
        0
        Fantastic.
         
        Thanks, Exactly what I was looking for.

         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9