Displaying Time-Based Greetings

Posted: May 1, 2010 in Logon Script with Shell
Tags:


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:

  1. Create a new directory to store all files included in this example.
  2. 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s