Link to home
Start Free TrialLog in
Avatar of blee5
blee5

asked on

VB script to check date and run a different batch file depending on the day

Is there a way to create a vbscript that will run a certain batch file depending on the day. For example on if it is monday irun batch file A if tuesday run batch file B etc.
ASKER CERTIFIED SOLUTION
Avatar of dmitryz6
dmitryz6

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This will do what you asked literally... if the batch file names were just representative then creating an array of the real names and using iDay as an index will work, too.

Option Explicit
Dim dToday   :  dToday = date
Dim iDay     :  iDay   = Weekday(dToday)
Dim sBatch
Dim oShell
sBatch     = Chr(64 + iDay) & ".bat"
Wscript.Echo "ready to execute " & sBatch
Set oShell = CreateObject("Wscript.Shell")
oShell.Run sBatch, 1, False
Set oShell = Nothing


Here is the example using an array (allows batch file names to be whatever you want)

Option Explicit
Dim dToday    :  dToday = date
Dim iDay      :  iDay   = Weekday(dToday)
Dim sBatch
Dim oShell
Dim aBatch    :  aBatch = Array("a.bat", "b.bat", "c.bat", "d.bat", "e.bat", "f.bat")
sBatch     = aBatch(iDay - 1)
Wscript.Echo "ready to execute " & sBatch
Set oShell = CreateObject("Wscript.Shell")
oShell.Run sBatch, 1, False
Set oShell = Nothing

HTH,
Lynn
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial