I'm trying to have a batch file to perform different task based on hours (24h clock). It works, but not on every hour which is strange and I can't figure it out. What am I doing wrong here, could anyone help out? So if the clock is 2:33 it goes to :hour2 but when it's 4:33 it gives an error "(goto was unexpected at this time."
For /f %%# In ('WMIC Path Win32_LocalTime Get Hour^|Findstr [0-23]') Do (Set DOW=%%#)
echo %DOW% >NUL
IF %DOW%==0 (goto hour0)
IF %DOW%==1 (goto hour1)
IF %DOW%==2 (goto hour2)
IF %DOW%==3 (goto hour3)
IF %DOW%==4 (goto hour4)
IF %DOW%==5 (goto hour3)
IF %DOW%==6 (goto hour3)
IF %DOW%==7 (goto hour3)
IF %DOW%==8 (goto hour3)
IF %DOW%==9 (goto hour9)
IF %DOW%==10 (goto hour10)
IF %DOW%==11 (goto hour11)
IF %DOW%==12 (goto hour12)
IF %DOW%==13 (goto hour13)
IF %DOW%==14 (goto hour14)
IF %DOW%==15 (goto hour15)
IF %DOW%==16 (goto hour16)
IF %DOW%==17 (goto hour17)
IF %DOW%==18 (goto hour18)
IF %DOW%==19 (goto hour19)
IF %DOW%==20 (goto hour20)
IF %DOW%==21 (goto hour21)
IF %DOW%==22 (goto hour22)
IF %DOW%==23 (goto hour23)
:hour0
echo it's now hour 0
goto finish
...[All hours repeated exactly the same]...
:finish
I expected WMIC Path Win32_LocalTime Get Hour to work with this one. As standalone it results string "Hour 4", but the batch file doesn't somehow recognize all the hours.