0

I'm trying to make a login batch file that starts a few services but in a way that the user knows they are being started. So I thought I'd use a batch script for that.

The script is working fine, but I wanted to embellish it a bit more using the logo in ASCII and use colors. Everything is working fine on my development PC (Windows 10 64-bit), but on the user machines (Windows 7 64-bit) the colors are not being shown.

I'm using:

echo <ESC>[93m Logging in

But when I run it, I displays:

←[93m Logging in

So it's not treating the ESC properly. The issue has to be PC based because it's working on another machine, but I don't know how to solve this.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Cainnech
  • 439
  • 1
  • 5
  • 17

3 Answers3

1

Only console of Windows 10 supports ESC sequences as documented on MSDN page Console Virtual Terminal Sequences. Console host of previous Windows versions don't support ANSI ESC sequences.

There is the command COLOR to define text color and background color.

Open a command prompt window and run color /? for help on this command.

Hundreds of batch file examples on how to use COLOR can be found on Stack Overflow for example with the search term [batch-file] color.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • I understand the use of COLOR but I want use multiple colors in the same batch-file. COLOR sets the color for the entire batch. – Cainnech Jan 04 '17 at 16:14
  • 2
    Click on search term link I provided and you can see also solutions for coloring just parts of the console window. See for example [How to have multiple colors in a Windows batch file?](http://stackoverflow.com/questions/4339649/) ANSI ESC sequences are not supported by console host of Windows prior Windows 10. That is a fact. – Mofi Jan 04 '17 at 16:17
  • @Cainnech If you are using Windows 10, maybe it's the ESC character that's the problem? You might try `forfiles /p . /m "%~nx0" /c "cmd /c echo 0x1B[93mLogging in0x1B[0m"` and see whether you have better luck. The `0x1B` gets converted by `forfiles` into the ESC character. – rojo Jan 04 '17 at 16:42
  • @rojo I tried it but no luck I'm afraid. I'm getting the same message as in the original tests. – Cainnech Jan 04 '17 at 17:04
  • @mofi I tried your suggestion but unfortunately without any luck: > echo off echo( call :ColorText 0C "TEST" echo. echo. pause goto :eof :ColorText echo off "%~2" findstr /v /a:%1 /R "^$" "%~2" nul del "%~2" > nul 2>&1 goto :eof – Cainnech Jan 04 '17 at 17:05
0

As mented befoer me, windows prior 10 does not support escape sequences. You could try ANSICON

user2956477
  • 1,208
  • 9
  • 17
0

the old ANSI.SYS, which was loaded at boot time would interpret color commands such as [esc][1;33;40m (where [esc] was a small arrow) as the foreground and background colors for text in the DOS prompt window, or outside of windows in a DOS session. (Worked in Windows 3.1x, Win 95, Win 98 1st and 2nd, Win ME and perhaps even 32 bit Win XP.)

However,after the introduction of 64-bit systems, ANSI.SYS no longer works as before. The command "color" in a Windows 7 cmd.exe window colors the ENTIRE window text, not just the part you want to color. I understand some of this has been alleviated in Win 10 cmd.exe, but except for that...

There may be a possible solution: called "CoColor" by Horst Schaeffer

Freeware © Horst Schaeffer -- Contact: horst.schaeffer@gmail.com

http://www.horstmuc.de/wcon.htm

Here is what he says about it:

CoColor 2.1 Change console output color Download 32 bit (6Kb) Download 64 bit (7Kb)

CoColor changes the console color for the succeeding console output, not for the entire window, like the built-in COLOR command. CoColor uses the same color codes as COLOR.

CoColor also accepts a sequence of color codes and text strings (each in double quote marks), making it a colorful ECHO replacement. Non-ASCII characters will be handled the same way as by ECHO.

Demo.CMD is included.

(NOTE: After running Demo.cmd you will need to run the command color to return to the default colors of the screen. He did not include that in his script.)

After scanning the files with Avast Antivirus, SuperAntiSpyware and Malwarebytes, I ran the CoColor 64-bit version on Win 7 Pro 64-bit and it seems to work well.

I wrote a lot of batches back in the old days with color bars for the lines of text. They did NOT change the color of the entire screen as does the "color" command in cmd.exe! COMMAND.COM understood color commands with ANSI.SYS loaded at boot time in the CONFIG.SYS. This is the closest thing I've seen yet to that original functionality. Hope this helps.

Cliff
  • 1