Thursday, July 05, 2012

How to 'Run As' multiple programs using a script in windows

As a system engineer or as a developer sometimes you may need to run multiple programs at once as a sequence or, one by one after some intervals. Following is a VB script created for specific purpose.

  • weAdmin\imAdmin - Specific use for "Run As"
  • C:\Test\Test1\Test1.exe - Path and file name
  • admin1234 - Password for the specific user.
  • 100 - Some waiting time to initialize 'run as'
  • 1000 - waiting time until next program run. (Configure this as you want)
Option explicit
Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test1\Test1.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234" 
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test2\Test2.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test3\Test3.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test4\Test4.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

Wscript.Quit

1 comment: