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.
blee5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dmitryz6Commented:
if Weekday(date) =1 then   '<-start sunday
    Shell "c:\test.bat"
elseif Weekday(date) =2 then
    Shell "c:\test1.bat"
elseif Weekday(date) =3 then
   Shell "c:\test2.bat"
end if

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
Or...

Select Case DatePart("w", Now())
    Case 1:
        MsgBox "Sunday"
       
    Case 2:
        MsgBox "Monday"
       
    Case 3:
        MsgBox "Tuesday"
       
    Case 4:
        MsgBox "Wednesday"
       
    Case 5:
        MsgBox "Thursday"
       
    Case 6:
        MsgBox "Friday"
       
    Case 7:
        MsgBox "Saturday"

End Select
JesterTooCommented:
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
JesterTooCommented:
Small correction to compensate for Monday = 2nd day of week instead of 1st day of week...

Option Explicit
Dim dToday   :  dToday = date
Dim iDay     :  iDay   = Weekday(dToday) - 1
Dim sBatch
Dim oShell
If iDay = 0 Then iDay = 1
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) - 1
Dim sBatch
Dim oShell
Dim aBatch    :  aBatch = Array("a.bat", "b.bat", "c.bat", "d.bat", "e.bat", "f.bat")
If iDay = 0 Then iDay = 1
sBatch     = aBatch(iDay - 1)
Wscript.Echo "ready to execute " & sBatch
Set oShell = CreateObject("Wscript.Shell")
oShell.Run sBatch, 1, False
Set oShell = Nothing


Lynn
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.