Want to automate few process and when i install some application at the end it ask to click on finish button and then it asks for restart, i want to automate this process, so how can click that button using vbscript and run shutdown -r -t 0 using script..

Please Help!!

0 Comments   [ + ] Show Comments


Please log in to comment



Use this code (TEST is the name of the app):

Set oShell = CreateObject("WScript.Shell")

If oShell.AppActivate("TEST") Then

oShell.SendKeys "%{F4}"

oShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

End If 
Answered 08/22/2013 by: mattski
Second Degree Green Belt

  • Interesting suggestion mattski - but F4 could be viewed as a forceful exit to the application, and may not return a valid INSTALL_RESULT (if that's being tracked). Perhaps something like AutoIT would be the solution here?
    • Yes AutoIT can be an option too...I see what you mean in the force key issue...what I would do is find out what is the last button being displayed in the app and then get SendKeys to trigger it. To help out here is a list of keys that can be triggered using my script (thanks to http://ss64.com/vb/sendkeys.html):

      Key SendKey Equivalent Description
      ~ {~} send a tilde (~)
      ! {!} send an exclamation point (!)
      ^ {^} send a caret (^)
      + {+} send a plus sign (+)
      Alt {ALT} send an Alt keystroke
      Backspace {BACKSPACE} send a Backspace keystroke
      Clear {CLEAR} Clear the field
      Delete {DELETE} send a Delete keystroke
      Down Arrow {DOWN} send a Down Arrow keystroke
      End {END} send an End keystroke
      Enter {ENTER} send an Enter keystroke
      Escape {ESCAPE} send an Esc keystroke
      F1 through F16 {F1} through {F16} send the appropriate Function key
      Page Down {PGDN} send a Page Down keystroke
      Space {SPACE} send a Spacebar keystroke
      Tab {TAB} send a Tab keystroke
      • Great stuff - if you can determine the tab order to arrive at the "Finish" button, I'd say sending the Enter would suffice
  • Thanks for ur help!! this is very new to me and will implement and get back to you..Thanks Again!! Cheers!!
  • mattski can u please suggest me how can i trigger (wait) that click button script untill that last finish button screen appears. suppose any setup.exe process is running but when but that last screen appears at that time also that setup.exe is running so unable to detect when to trigger it
  • Add the following two lines below the first line of code I made previously:

    oShell.Run "name of your installer", 9
    WScript.Sleep 500


    first run your application using the 9 switch for Maximising and Activating the app.
    then sleep for amount of seconds - just tweak the number to suit.

    Coincidentally, what kind of application are you running? Any chance you can make the app run unattended using the silent switches etc? this would save you the above vbscript to run.
Please log in to comment
Answer this question or Comment on this question for clarity