China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 05:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] When using ANSI.SYS, how to set the background color of the CMD window? View 2,562 Replies 17
Original Poster Posted 2008-10-05 11:58 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Found such code on the forum, very classic (displaying colored text in CMD).

But I don't understand how to set the overall background color.

The default foreground and background are black and white.

If I want the background to be green (color 2)

That is: change the black background in the picture to green? Image link address

How to set it? Please help everyone?


@echo off
:: Display colored text in CMD
chcp 437>nul&&graftabl 936>nul
if not exist CONFIG.NT copy %WinDir%\System32\CONFIG.NT CONFIG.NT
@cls
echo DEVICE=%WinDir%\System32\ANSI.SYS /x >%WinDir%\System32\CONFIG.NT
@echo.
command /cecho 
command /cecho 




























































jing

[ Last edited by 516526966 on 2008-10-8 at 02:47 ]
Floor 2 Posted 2008-10-06 14:58 ·  中国 山东 淄博 联通
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Waiting online for everyone's help?????

Is there no expert willing to help?

[ Last edited by 516526966 on 2008-10-6 at 15:32 ]
Floor 3 Posted 2008-10-06 17:15 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
←[ is equivalent to the start符
m  is equivalent to the end符
;  is equivalent to the separator




It will have a background color if changed to something similar to the above. (I can't test here, you can try it)
┌───────┐
├→学习→实践→┤
└───────┘
Floor 4 Posted 2008-10-06 17:21 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Also, your question should be revised. It shouldn't be about setting the window background color. If that's the case, just add a line at the beginning of the batch file like

color 21
and so on.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 5 Posted 2008-10-07 19:57 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Originally posted by wxcute at 2008-10-6 05:21 PM:
You should also modify your question. It shouldn't be about setting the window background color.
If that's the case, add a line at the beginning of the batch script like

color 21
or something like that.


Dude, I'm talking about setting the background color of the window,

Not the background color of the font,

I know that color sets the background and font.

But it always remains the default black-and-white interface.
Floor 6 Posted 2008-10-08 02:47 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Request the help of the great experts?
Floor 7 Posted 2008-10-08 20:40 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Great experts, please help me.

Please. The younger brother is waiting? Why no one pays attention to me
Floor 8 Posted 2008-10-10 16:12 ·  中国 山东 淄博 联通
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Brothers, please help my younger brother. Waiting for a reply.
Floor 9 Posted 2008-10-11 00:09 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Again, I ask for help. Or maybe some guidance is also okay. I didn't find relevant tutorials.
Floor 10 Posted 2008-10-15 15:09 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Really discouraged. Is there really no one who knows? Or what reason is there for no one to reply.
Floor 11 Posted 2008-10-15 15:22 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
What is the difference between the background color of the window and the background color of the font?
Floor 12 Posted 2008-10-15 15:42 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Floor 13 Posted 2008-10-15 15:46 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Add color 2a under @echo off. As shown in the following figure:
Attachments
难道不是这样吗.gif
┌───────┐
├→学习→实践→┤
└───────┘
Floor 14 Posted 2008-10-16 01:20 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Originally posted by wxcute at 2008-10-15 03:46 PM:
Add color 2a under @echo off

As shown in the following figure:



Why can't mine work? I'm using Windows 2003

What testing environment are you using.
Floor 15 Posted 2008-10-16 01:23 ·  中国 山东 淄博 电信
初级用户
Credits 63
Posts 37
Joined 2008-08-09 11:46
18-year member
UID 123026
Gender Male
Status Offline
Originally posted by 516526966 at 2008-10-16 01:20 AM:

Why can't mine work? I'm using Windows 2003.

What testing environment are you using?


Test results under Windows 2003

Why is mine like this.

[ Last edited by 516526966 on 2008-10-16 at 01:25 ]
Attachments
2008-10-16_010311.jpg
Forum Jump: