From: jeronimo on
Is there a way when running vb scripts in the console to change the
color of the output dynamically.

if error wscript.stdOut {in RED} "some error"

if info wscript.stdOut {in White} "some error"

etc.

?

Any thoughts or help would be appreciated.

Thank you!

From: Jim Gregg on
As far as I know, there is no way to actually do this on a line by line
basis such as you are asking. There was some discussion a while back
about creating a batch file that opened a cmd window, set colors, etc
and then executed the vbscript using cscript. I believe this would
allow you to set text colors, but again, not on a line by line basis as
such. If you want to do some fancy formatting with your output, look
into using IE as your output window. This would give you access to a
lot of formatting capabilities.

From: mr_unreliable on
hi Jeronimo,

You can change the color of console messages, but you are
going to have to use system api's to do it, and you are
(most likely) going to have to use another language, like
vb are autoit, which supports api's and typedef's.

These are the api's in question:

'-------------------------------------------------
' API declarations to manipulate the console
'-------------------------------------------------
Declare Function AllocConsole Lib "kernel32" () As Long
Declare Function FreeConsole Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long)
As Long
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA"
(ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal
nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long,
lpReserved As Any) As Long
Declare Function SetConsoleCtrlHandler Lib "kernel32" (ByVal
HandlerRoutine As Long, ByVal Add As Long) As Long

'-------------------------------------------------
' (more) API declarations, to embellish ms's code...
'-------------------------------------------------
Declare Function GetConsoleTitle Lib "kernel32" Alias "GetConsoleTitleA"
(ByVal lpConsoleTitle As String, ByVal nSize As Long) As Long
Declare Function SetConsoleTitle Lib "kernel32" Alias "SetConsoleTitleA"
(ByVal lpConsoleTitle As String) As Long
'
Declare Function GetConsoleScreenBufferInfo Lib "kernel32" (ByVal
hConsoleOutput As Long, lpConsoleScreenBufferInfo As
CONSOLE_SCREEN_BUFFER_INFO) As Long
' Declare Function WriteConsoleOutputAttribute Lib "kernel32" (ByVal
hConsoleOutput As Long, lpAttribute As my_Attrib, ByVal nLength As Long,
dwWriteCoord As COORD, lpNumberOfAttrsWritten As Long) As Long
Declare Function WriteConsoleOutputAttribute Lib "kernel32" (ByVal
hConsoleOutput As Long, ByVal wAttribute As Long, ByVal nLength As Long,
dwWriteCOORD As COORD, lpNumberOfAttrsWritten As Long) As Long
' Declare Function FillConsoleOutputAttribute Lib "kernel32" (ByVal
hConsoleOutput As Long, ByVal wAttribute As Long, ByVal nLength As Long,
dwWriteCoord As COORD, lpNumberOfAttrsWritten As Long) As Long
Declare Function FillConsoleOutputAttribute Lib "kernel32" (ByVal
hConsoleOutput As Long, ByVal wAttribute As Long, ByVal nLength As Long,
ByVal dwWriteCOORD As Long, lpNumberOfAttrsWritten As Long) As Long
' Declare Function FillConsoleOutputCharacter Lib "kernel32" Alias
"FillConsoleOutputCharacterA" (ByVal hConsoleOutput As Long, ByVal
cCharacter As Byte, ByVal nLength As Long, dwWriteCoord As COORD,
lpNumberOfCharsWritten As Long) As Long
Declare Function FillConsoleOutputCharacter Lib "kernel32" Alias
"FillConsoleOutputCharacterA" (ByVal hConsoleOutput As Long, ByVal
cCharacter As Byte, ByVal nLength As Long, ByVal dwWriteCOORD As Long,
lpNumberOfCharsWritten As Long) As Long
Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal
hConsoleOutput As Long, ByVal wAttributes As Long) As Long
'
Declare Function GetLastError Lib "kernel32" () As Long

' Declare Function SetConsoleCursorPosition Lib "kernel32" (ByVal
hConsoleOutput As Long, dwCursorPosition As COORD) As Long
Declare Function SetConsoleCursorPosition Lib "kernel32" (ByVal
hConsoleOutput As Long, ByVal dwCurPosCOORD As Long) As Long
----------------------------------

The api used to set text colors is: "SetConsoleTextAttribute".

There used to be vb (classic) demos on how to manipulate the
console on the vb source code sites, but sadly many of those
sites are now closed, or converted over to "vb.Net" code.

I have attached a couple of graphic files, showing what you can
do with the api's (sorry if you are running dialup)...

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


jeronimo wrote:
> Is there a way when running vb scripts in the console to change the
> color of the output dynamically.
From: mr_unreliable on
Also, a less onerous possibility -- if you can get it to work
-- is an old DOS "ansi.sys" utility. In DOS, if you loaded
this utility, you could change the colors (and other attributes
of console messages) via "excape codes".

Here is some documentation:

http://www.computerhope.com/ansisys.htm

Finding it may be more difficult, you may have to go back to
an old DOS 3.3 distribution _diskette_ (remember diskettes?).

Then you are going to have to get ansi.sys to work with your
system. For this, you may have better luck if your system
is win9x. Good Luck.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)



jeronimo wrote:
> Is there a way when running vb scripts in the console to change the
> color of the output dynamically.
>
> if error wscript.stdOut {in RED} "some error"
>
> if info wscript.stdOut {in White} "some error"
>
> etc.
>
> ?
>
> Any thoughts or help would be appreciated.
>
> Thank you!
>
From: mr_unreliable on
I may have spoken too soon.

Apparently ansi.sys _WILL_ work with win95, 98, nt, 2k and xp.

All you need to do is add the following to your config.sys file.

DEVICEHIGH=C:\WINDOWS\COMMAND\ANSI.SYS

This is based on a more careful reading of the above linked page.

Once ansi.sys is loaded it will control the console display, and
then you just insert the appropriate "escape codes" in your text.

cheers, jw

mr_unreliable wrote:
> Then you are going to have to get ansi.sys to work with your
> system. For this, you may have better luck if your system
> is win9x. Good Luck.
>
> cheers, jw
 | 
Pages: 1
Prev: modifying "name" attribute in AD.
Next: vbs -> HTA