Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 252 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to echo with different colors in the Windows command line

#1
I know that the `color bf` command sets the colors of the whole command line window but I wanted to to print one single line in a different color.
Reply

#2
you could use cecho.. you can also use it to embed right into your script so you dont have to carry along a .com or .exe

[To see links please register here]

Reply

#3
I was annoyed by the lack of proper coloring in cmd too, so I went ahead and created **cmdcolor**. It's just an stdout proxy, which looks for a limited set of ANSI/VT100 control sequences (in other words, like in bash), i.e. `echo \033[31m RED \033[0m DEFAULT | cmdcolor.exe`.

[Usage and downloads][1].

[1]:

[To see links please register here]

Reply

#4
I looked at this because I wanted to introduce some simple text colors to a Win7 Batch file. This is what I came up with. Thanks for your help.

@echo off
cls && color 08

rem .... the following line creates a [DEL] [ASCII 8] [Backspace] character to use later
rem .... All this to remove [:]
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")

echo.

<nul set /p="("
call :PainText 09 "BLUE is cold" && <nul set /p=") ("
call :PainText 02 "GREEN is earth" && <nul set /p=") ("
call :PainText F0 "BLACK is night" && <nul set /p=")"
echo.
<nul set /p="("
call :PainText 04 "RED is blood" && <nul set /p=") ("
call :PainText 0e "YELLOW is pee" && <nul set /p=") ("
call :PainText 0F "WHITE all colors"&& <nul set /p=")"

goto :end

:PainText
<nul set /p "=%DEL%" > "%~2"
findstr /v /a:%1 /R "+" "%~2" nul
del "%~2" > nul
goto :eof

:end
echo.
pause
Reply

#5
Put the following lines into a file called `ColourText.bas` on your desktop.

Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module MyApplication
Public Declare Function GetStdHandle Lib "kernel32" Alias "GetStdHandle" (ByVal nStdHandle As Long) As Long
Public Declare Function SetConsoleTextAttribute Lib "kernel32" Alias "SetConsoleTextAttribute" (ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long
Public Const STD_ERROR_HANDLE = -12&
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&

Sub Main()
Dim hOut as Long
Dim Ret as Long
Dim Colour As Long
Dim Colour1 As Long
Dim Text As String
hOut = GetStdHandle(STD_OUTPUT_HANDLE)
Colour = CLng("&h" & Split(Command(), " ")(0))
Colour1 = Clng("&h" & Split(Command(), " ")(1))
Text = Mid(Command(), 7)
Ret = SetConsoleTextAttribute(hOut, Colour)
Console.Out.WriteLine(text)
Ret = SetConsoleTextAttribute(hOut, Colour1)
End Sub
End Module

Save it and type the following in a command prompt.

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%userprofile%\desktop\ColourText.exe" "%userprofile%\desktop\ColourText.bas" /verbose

A file called ColourText.exe will appear on your desktop. **Move it to the Windows folder**.

To use you must use two character codes to set colour eg `01` not `1`.

ColourText ColourOfText ColourOfTextWhenFinished Text

EG To set blue on white by not passing any text, then red on white text, finishing with blue on grey.

ColourText F1 F1
ColourText F2 71 This is green on white

or

ColourText F1 F1
cls
ColourText F4 F4
Echo Hello
Echo Hello today
ColourText F1 F1

Also the `CLS` command becomes interesting. `Color` command without parameters resets all colours to startup colours.

To get the colour code add the following numbers together. Use Calculator in programmers mode. These are hex numbers. They can be added together eg Red + Blue + FG Intensity = 13 = D. As 10+ wasn't used the background will be black. Colour codes MUST be two characters, eg `08` not `8`.

FOREGROUND_RED = &H4 ' text color contains red.
FOREGROUND_INTENSITY = &H8 ' text color is intensified.
FOREGROUND_GREEN = &H2 ' text color contains green.
FOREGROUND_BLUE = &H1 ' text color contains blue.
BACKGROUND_BLUE = &H10 ' background color contains blue.
BACKGROUND_GREEN = &H20 ' background color contains green.
BACKGROUND_INTENSITY = &H80 ' background color is intensified.
BACKGROUND_RED = &H40 ' background color contains red.


Reply

#6
To get this working on Windows 10, you can enable this flag: `ENABLE_VIRTUAL_TERMINAL_PROCESSING`.

With this registry key you can set this by default

`[HKCU\Console] VirtualTerminalLevel dword 0x1`
Reply

#7
You can just creates files with the name of the word to print, uses findstr which can print in color, and then erases the file. Try this example:

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)

call :ColorText 0a "green"
call :ColorText 0C "red"
call :ColorText 0b "cyan"
echo(
call :ColorText 19 "blue"
call :ColorText 2F "white"
call :ColorText 4e "yellow"

goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

Run `color /?` to get a list of colors.
Reply

#8
This is a self-compiled **bat/.net hybrid** (should be saved as `.BAT`) that can be used on any system that have installed .net framework (it's a rare thing to see an windows without .NET framework even for the oldest XP/2003 installations) . It uses jscript.net compiler to create an exe capable to print strings with different background/foreground color only for the current line.


@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal

for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
set "jsc=%%v"
)

if not exist "%~n0.exe" (
"%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)

%~n0.exe %*

endlocal & exit /b %errorlevel%

*/

import System;

var arguments:String[] = Environment.GetCommandLineArgs();

var newLine = false;
var output = "";
var foregroundColor = Console.ForegroundColor;
var backgroundColor = Console.BackgroundColor;
var evaluate = false;
var currentBackground=Console.BackgroundColor;
var currentForeground=Console.ForegroundColor;


//http://stackoverflow.com/a/24294348/388389
var jsEscapes = {
'n': '\n',
'r': '\r',
't': '\t',
'f': '\f',
'v': '\v',
'b': '\b'
};

function decodeJsEscape(_, hex0, hex1, octal, other) {
var hex = hex0 || hex1;
if (hex) { return String.fromCharCode(parseInt(hex, 16)); }
if (octal) { return String.fromCharCode(parseInt(octal, 8)); }
return jsEscapes[other] || other;
}

function decodeJsString(s) {
return s.replace(
// Matches an escape sequence with UTF-16 in group 1, single byte hex in group 2,
// octal in group 3, and arbitrary other single-character escapes in group 4.
/\\(?:u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(.))/g,
decodeJsEscape);
}


function printHelp( ) {
print( arguments[0] + " -s string [-f foreground] [-b background] [-n] [-e]" );
print( " " );
print( " string String to be printed" );
print( " foreground Foreground color - a " );
print( " number between 0 and 15." );
print( " background Background color - a " );
print( " number between 0 and 15." );
print( " -n Indicates if a new line should" );
print( " be written at the end of the ");
print( " string(by default - no)." );
print( " -e Evaluates special character " );
print( " sequences like \\n\\b\\r and etc ");
print( "" );
print( "Colors :" );
for ( var c = 0 ; c < 16 ; c++ ) {

Console.BackgroundColor = c;
Console.Write( " " );
Console.BackgroundColor=currentBackground;
Console.Write( "-"+c );
Console.WriteLine( "" );
}
Console.BackgroundColor=currentBackground;



}

function errorChecker( e:Error ) {
if ( e.message == "Input string was not in a correct format." ) {
print( "the color parameters should be numbers between 0 and 15" );
Environment.Exit( 1 );
} else if (e.message == "Index was outside the bounds of the array.") {
print( "invalid arguments" );
Environment.Exit( 2 );
} else {
print ( "Error Message: " + e.message );
print ( "Error Code: " + ( e.number & 0xFFFF ) );
print ( "Error Name: " + e.name );
Environment.Exit( 666 );
}
}

function numberChecker( i:Int32 ){
if( i > 15 || i < 0 ) {
print("the color parameters should be numbers between 0 and 15");
Environment.Exit(1);
}
}


if ( arguments.length == 1 || arguments[1].toLowerCase() == "-help" || arguments[1].toLowerCase() == "-help" ) {
printHelp();
Environment.Exit(0);
}

for (var arg = 1; arg <= arguments.length-1; arg++ ) {
if ( arguments[arg].toLowerCase() == "-n" ) {
newLine=true;
}

if ( arguments[arg].toLowerCase() == "-e" ) {
evaluate=true;
}

if ( arguments[arg].toLowerCase() == "-s" ) {
output=arguments[arg+1];
}


if ( arguments[arg].toLowerCase() == "-b" ) {

try {
backgroundColor=Int32.Parse( arguments[arg+1] );
} catch(e) {
errorChecker(e);
}
}

if ( arguments[arg].toLowerCase() == "-f" ) {
try {
foregroundColor=Int32.Parse(arguments[arg+1]);
} catch(e) {
errorChecker(e);
}
}
}

Console.BackgroundColor = backgroundColor ;
Console.ForegroundColor = foregroundColor ;

if ( evaluate ) {
output=decodeJsString(output);
}

if ( newLine ) {
Console.WriteLine(output);
} else {
Console.Write(output);

}

Console.BackgroundColor = currentBackground;
Console.ForegroundColor = currentForeground;




Here's the help message:

[![enter image description here][1]][1]

**Example**:

`coloroutput.bat -s "aa\nbb\n\u0025cc" -b 10 -f 3 -n -e`

You can also find this script [here][2].

You can also check carlos' color function ->

[To see links please register here]



[1]:

[2]:

[To see links please register here]

Reply

#9
This isn't a great answer, but if you know the target workstation has Powershell you can do something like this (assuming BAT / CMD script):

CALL:ECHORED "Print me in red!"

:ECHORED
%Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -foregroundcolor Red %1
goto:eof

---
Edit: <sub><sup>(now simpler!)</sup></sub>
=
It's an old answer but I figured I'd clarify & simplify a bit

![img][1]

[PowerShell][2] is now [*included* in all versions][3] of Windows since 7. Therefore the syntax for this answer can be shortened to a simpler form:

- the **path** doesn't need to be specified since it should be in the environment variable already.
- **unambiguous** commands can be [abbreviated][4]. For example you can:
- use `-fore` instead of `-foregroundcolor`
- use `-back` instead of `-backgroundcolor`
- the command can also basically be used '**inline**' in place of `echo`
(rather than creating a separate batch file as above).

---
Example:
-
powershell write-host -fore Cyan This is Cyan text
powershell write-host -back Red This is Red background

---
More Information:
-
The complete list of colors and more information is available in the
- **PowerShell [Documentation for `Write-Host`][5]**


[1]:

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply

#10
An alternative is to use **NodeJS**.

Here is an example:

const os = require('os');
const colors = require('colors');

console.log("Operative System:".green,os.type(),os.release());
console.log("Uptime:".blue,os.uptime());
And this is the result:

[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through