dcandygmailcom

Changes the colour of text in the command prompt. Unlike inb

Feb 12th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.46 KB | None | 0 0
  1. REM Three files follow
  2. REM ColourText.bat
  3. REM This file compiles ColourText.vb to ColourText.exe using the system VB.NET compiler.
  4. REM ColourText.exe Changes the colour of text in the command prompt. Unlike inbuilt commands it can change just one line.
  5. "C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\ColourText.exe" "%~dp0\ColourText.vb" /verbose
  6. pause
  7.  
  8.  
  9. --------------------------------------------------
  10.  
  11. 'ColourText.vb
  12. Imports System
  13. Imports System.IO
  14. Imports System.Runtime.InteropServices
  15. Imports Microsoft.Win32
  16.  
  17. Public Module MyApplication  
  18. Public Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Integer) As Integer
  19. Public Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal hConsoleOutput As Integer, ByVal wAttributes As Integer) As Integer
  20. Public Const STD_ERROR_HANDLE = -12&
  21. Public Const STD_INPUT_HANDLE = -10&
  22. Public Const STD_OUTPUT_HANDLE = -11&
  23.  
  24. Sub Main()
  25.     Dim hOut as Integer
  26.     Dim Ret as Integer
  27.     Dim Colour As Integer
  28.     Dim Colour1 As Integer
  29.     Dim Text As String
  30.     hOut  = GetStdHandle(STD_OUTPUT_HANDLE)
  31.     Colour = CLng("&h" & Split(Command(), " ")(0))
  32.     Colour1 = Clng("&h" & Split(Command(), " ")(1))
  33.     Text = Mid(Command(), 7)
  34.     Ret = SetConsoleTextAttribute(hOut,  Colour)
  35.     Console.Out.WriteLine(text)
  36.     Ret = SetConsoleTextAttribute(hOut, Colour1)
  37. End Sub
  38. End Module
  39.  
  40.  
  41. -----------------------------------------------
  42.  
  43. ColourTextHelp.txt
  44.  
  45. To use
  46. ColourText <ColourOfText> <ColourOfTextWhenFinished> [Text]
  47.  
  48. Also the CLS command becomes interesting. Color command without parameters resets all colours to startup colours.
  49.  
  50. 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.
  51.  
  52. Colour codes MUST be two characters, eg 08 not 8.
  53.  
  54. FOREGROUND_RED = &H4     '  text color contains red.
  55. FOREGROUND_INTENSITY = &H8     '  text color is intensified.
  56. FOREGROUND_GREEN = &H2     '  text color contains green.
  57. FOREGROUND_BLUE = &H1     '  text color contains blue.
  58. BACKGROUND_BLUE = &H10    '  background color contains blue.
  59. BACKGROUND_GREEN = &H20    '  background color contains green.
  60. BACKGROUND_INTENSITY = &H80    '  background color is intensified.
  61. BACKGROUND_RED = &H40    '  background color contains red.
  62.  
  63.  
  64. So black background is 0 while white is F0 (adding 10 + 20 + 40 + 80). Red on white is f4.
Advertisement
Add Comment
Please, Sign In to add comment