Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to include some ANSI codes into a batch file to add a little color. I've noticed that ANSI.SYS isn't loaded by default in WinXP, but even when I do add DEVICE=ANSI.SYS to my C:\WINDOWS\system32\config.nt file and reboot, it doesn't recognize the codes (just displays them as plain text). I have a copy of ANSI.COM as well, but it doesn't recognize them, either. I made the Escape character in Edit (Ctrl-P, then Escape). Am I doing something wrong, or is WinXP just not friendly to ANSI codes?
Here's an example:
echo [0m[2J[12;34H[37;44;1mHello World
You can't enable ANSI escape codes in Windows XP because it is a NT kernel based system, while ANSI.SYS requires a DOS core and command.com interpreter (cmd.exe in WinXP) as Windows 9X/ME or legacy DOS/Win 3X systems.
So forget escape codes, but you can achieve a bit of colour by using the color command.
To get what you want codecolor 1F
See color /? for other choices.

You can only use ANSI.SYS in the COMMAND.COM interpreter, which is included in Windows for compatibility with old MS-DOS applications, and runs in the 16-bit Virtual DOS Machine.
Run COMMAND.COM if you really must, but note that it runs slower than CMD.exe (the native 32-bit Windows command interpreter), and contains many restrictions such as not supporting long file names or any of the newer batch commands.

Argh... I was afraid you'd say that. That's a shame. Ah well, the COLOR command is the way I'll go, then. Thanks!!!

I've always wondered how you have to use colored text in a DOS window under WinXP and such. The COLOR command sets the whole box in different fore- and/or backgroundcolor.
... but no line or string of text ?
Do I have to get my ancient C-compiler again ?
Hi there.

What programming language do you use at the moment, if you've given up C? If you're after something modern, you can use the win32api package from Python for Windows Extensions.

Just because I was curious if I could get it to work, I decided to try using the COMMAND.COM to utilize ANSI.SYS. It worked! Here's what I did (just for information's sake):
1. Created a new file - C:\WINDOWS\system32\ANSI.NT
2. Saved the new file with these contents:
dosonly
device=%systemroot%\system32\ansi.sys
device=%SystemRoot%\system32\himem.sys
files=40
dos=high,umb
3. Created a shortcut to C:\WINDOWS\system32\COMMAND.COM
4. Right-clicked the shortcut, selected Properties, and clicked the Advanced button on the Program tab.
5. Changed the "Config filename" field to point at my new ANSI.NT file (I left the "Autoexec filename" field the way it was)
6. Used that shortcut to open COMMAND.COM, used EDIT to create a test .BAT file (since .CMD files don't work in COMMAND.COM) that included some ANSI codes (I'm not sure of any other way to create escape code characters, except maybe copying and pasting them from pre-existing files).
7. When I then ran the batch file, it recognized all the codes I put in there.I may try to figure out a way to call COMMAND.COM with the new ANSI.NT from a standard .CMD file and see how that goes.
Thanks for your help, everyone!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |