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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Shel
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.Shel
oShell.Run sBatch, 1, False
Set oShell = Nothing
HTH,
Lynn