How can I print color text under "cmd.exe" in windows XP

Posted on 2004-11-21
Last Modified: 2013-12-03
I've tried putting ansi.sys into config.nt, but later discovered that this is not relevant to "cmd.exe" (and obviously, ansi escape sequences don't just work without something to handle them).

I've tried writing a driver to call int 10h, but this blows up on the int 10h call with the following error:-
    Unhandled exception ...: 0xC0000005: Access Violation.

I don't recall an INT21 interface for changing color. I can't find any hints in MSVC++ help, nor google.

I know cmd.exe can *do* color, since after dropping into NTVDM and doing color there, it returns and retains the color on the cmd.exe's screen (and the cmd.exe's output overwrites both the residual outputted text as well as the color attributes, so whatever output routine cmd.exe is using, it's programmed to *do* colour it seems; and of course you can set everything to colors other than black+white (see cmd.exe /?)... it's just not clear how to have colored output!)
Question by:ChrisDrake
    LVL 48

    Accepted Solution

    LVL 2

    Author Comment

    Awesome!  I *can't* beleive how long I spent both in Google *and* MSDN trying to hunt this down... It was of course there all the time; but as with almost all Microsoft technologies, if you don't know the obscure words/phrases MS have dreamed up for the concept (in this case - it was "SetConsoleTextAttribute()" ), you've got no chance of hunting it down.

    Anyways - I wrote me my own shiny new ANSI to SetConsoleTextAttribute() converting driver, and I'm happy-as now :-)

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now