The Hermit Hermit's Free Library  MS-DOS

A batch file which will set the background and foreground colors in a DOS Session (or DOS Mode) to one of several pre-determined color schemes. Demonstrates several batch features, including IF and GOTO, PROMPT, and ECHO.

Set Background and Foreground Colors in DOS

In order for DOSCOLOR.BAT to work you must first load the ANSI.SYS device driver and reboot your system. To load ANSI.SYS into an upper memory block from CONFIG.SYS, see the example given in Using HIMEM.SYS and EMM386.EXE.

Once you have loaded ANSI.SYS and pasted the lines below into a file with the .BAT extension, you can invoke the batch file from either the command line or from within your AUTOEXEC.BAT. If you use AUTOEXEC.BAT, be sure to use the form CALL DOSCOLOR [foreground color parameter][background color parameter].

Command line example (white on blue):

  DOSCOLOR WB

Autoexec.bat example (yellow on blue):

  CALL DOSCOLOR YB

The Batch File

@echo off
rem DOSCOLOR.BAT - sets screen colors for DOS session
rem Syntax: DOSCOLOR [foreground color][background color]
rem Example: DOSCOLOR WB
IF !NORMAL==!%1 GOTO %1
IF !INVERSE==!%1 GOTO %1
IF !WB==!%1 GOTO %1
IF !WR==!%1 GOTO %1
IF !WC==!%1 GOTO %1
IF !WG==!%1 GOTO %1
IF !WM==!%1 GOTO %1
IF !BB==!%1 GOTO %1
IF !YB==!%1 GOTO %1
IF !normal==!%1 GOTO %1
IF !inverse==!%1 GOTO %1
IF !wb==!%1 GOTO %1
IF !wr==!%1 GOTO %1
IF !wc==!%1 GOTO %1
IF !wg==!%1 GOTO %1
IF !wm==!%1 GOTO %1
IF !bb==!%1 GOTO %1
IF !yb==!%1 GOTO %1
GOTO HELP
:NORMAL
echo on
PROMPT $e[0m
GOTO SHOWPATH
:INVERSE
echo on
PROMPT $e[0;7m
GOTO SHOWPATH
:WB
echo on
PROMPT $e[0;44;37;1m
GOTO SHOWPATH
:WR
echo on
PROMPT $e[0;41;37;1m
GOTO SHOWPATH
:WC
echo on
PROMPT $e[0;46;37;1m
GOTO SHOWPATH
:WG
echo on
PROMPT $e[0;42;37;1m
GOTO SHOWPATH
:WM
echo on
PROMPT $e[0;45;37;1m
GOTO SHOWPATH
:WB
echo on
PROMPT $e[0;36;44;1m
GOTO SHOWPATH
:YB
echo on
PROMPT $e[0;44;33;1m
GOTO SHOWPATH
:normal
echo on
PROMPT $e[0m
GOTO SHOWPATH
:inverse
echo on
PROMPT $e[0;7m
GOTO SHOWPATH
:wb
echo on
PROMPT $e[0;44;37;1m
GOTO SHOWPATH
:wr
echo on
PROMPT $e[0;41;37;1m
GOTO SHOWPATH
:wc
echo on
PROMPT $e[0;46;37;1m
GOTO SHOWPATH
:wg
echo on
PROMPT $e[0;42;37;1m
GOTO SHOWPATH
:wm
echo on
PROMPT $e[0;45;37;1m
GOTO SHOWPATH
:bb
echo on
rem PROMPT $e[0;36;44;1m
rem PROMPT  [s [1;0m [1;50f$d $t$h$h$h Ardvark [0m [u$p$g
PROMPT  [s [1;0m [1;50f$d $t$h$h$h Ardvark [0m [u$e[0;36;44;1m$p$g
GOTO SHOWPATH
:yb
echo on
PROMPT $e[0;44;33;1m
GOTO SHOWPATH
:HELP
cls
ECHO.
ECHO                  DOSCOLOR.BAT requires a parameter
ECHO.
ECHO                     Enter one of the following:
ECHO.
ECHO                  DOSCOLOR NORMAL  (white on black)
ECHO                  DOSCOLOR INVERSE (black on white)
ECHO                  DOSCOLOR (F)oreground(B)ackground
ECHO.
ECHO                       available color choices
ECHO                                are
ECHO.
ECHO      White/Blue  Yellow/Blue  White/Red  White/Cyan  White/Mauve
ECHO.
GOTO END
:SHOWPATH
PROMPT $P$G
CLS
:END