Although it’s not essential, many administrators like to display a greeting to the user depending on the time of day. To display a time-based greeting from the command line, proceed as follows:
- Create a new directory to store all files included in this example.
- Select Start|Run and enter “scriptfile.bat.”
Here, scriptfile is the full path and file name of a script file that contains the following:
@Echo Off
CLS
For /F “Delims=: Tokens=1” %%I in (‘Time /T’) Do Set Hour=%%I
For /F “Delims=: Tokens=2” %%I in (‘Time /T’) Do Set Min=%%I
For /F “Delims=0,1,2,3,4,5,6,7,8,9 Tokens=2” %%I in
(‘Set Min‘) Do Set AP=%%I
If %AP% EQU p Goto PM
Set Greet=Good Morning
Goto End
: PM
If %Hour% EQU 12 Set Hour=0
If %Hour% LSS 12 Set Greet=Good Evening
If %Hour% LSS 6 Set Greet=Good Afternoon
:End
Echo %Greet%
Set Hour=
Set Min=
Set AP=
Note | The highlighted code above should be placed on one line. |
Here, the Time /T command indicates the local system time.