Different Colours in Batch Files

Published

Introduction: Different Colours in Batch Files

About: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope to become a programmer, although in what category is still a mystery (...

Everyone, with the help of g-one, I have created a function that you can install into your windows/system32 folder to get more than one colour in batch files.

Copy and paste the following code and save it as ncol.bat (this is very important that you save it exactly like that).

@echo off
setlocal
if "%~1"=="/?" (
echo.
echo    ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo          Remember that spaces cannot be added if you don't put the text in
echo          quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo          For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b


Once that is done, head over to your windows system32 folder and save it in there (C:\Windows\System32)

Read on for instructions...


Step 1: Instructions

Ok, how to use this function.

Firstly, type it in as you would any command "ncol"

The first parameter is the text you want converted.

The second parameter is the colour (must be correspondent to the colour command).

Example:

ncol "Hello" 10

Would output:

Hello


Just try it!

Note: If you have spaces, you must use quotation marks ("").

P.S: type in "ncol /?" for more help.

Unfortunately, special characters cannot be converted yet... (~!@#$%^&*()_+=-/,.<>":;'[]\{}|`)

And there is a little glitch with it, but other than that... It's good to go!

--EDIT--
To add more colors onto one line, use the && operator. E.g: ncol "Hello " 12 && ncol "there" 23
would output "Hello " in one color, and "there" in another.

Share

    Recommendations

    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest
    • Woodworking Contest

      Woodworking Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    25 Comments

    umm... when i do that i get

    '"Hello.@"' is not recognized as an internal or external command,
    operable program or batch file.
    FINDSTR: Cannot open *.@
    Could Not Find C:\Users\MyName\*.@

    No its fine, i found a different program that does the same thing but works. I still like ur idea though.

    2 replies

    Im making a movement simulator game in batch (Kind of like Terraria) And for every block is a character (or piece of text). I really want to save myself from writing over 300 variables. So is there a way to have arrays in batch?

    Everyone I made a version that works view it here

    https://www.instructables.com/id/Multiple-colors-in-cmd/

    Hey Pickle! just wanted to say thanks because your instructables have really helped me with getting into batch but just a question. Why don't you create any more instructables? it would be really nice if you had more :)

    2 replies

    but he doesn't post anymore does he? his last post was maybe 1 or 2 years ago. He used to be the person who fixed all my codes that didn't work and now i have piles of not working code

    Thanks, I've been trying to find a code for this. I'm thinking of using it in my Trivia.

    You should add here the *.@ file that you have in your system32 because we need that and thats why it isnt working

    It says the following when i type "ncol" in cmd.exe

    '".@"' is not recognized as an internal or external command,

    operable program or batch file.

    FINDSTR: Argument missing after /a

    Could not find C:\Users\****** ********\*.@

    6 replies

    NCOL is a function, meaning that you need to put in the name (ncol) and then the arguments. Type in "ncol /?" for more information.

    What exactly are you typing in? Are you still only putting in "ncol"?

    He is most likely seeing this:

    http://imgur.com/xf0MHJo

    As am I! :(

    As hard as I try, I can not recreate the issue on my computer. I don't really have any solid ideas as to why it is doing that for you and Mclover, but I will keep trying.

    I typed:
    ncol "Hello World" 10

    It worked for me on Windows 8, 7 and vista. What operating system are you using?

    It does not recognize "*.@"