Advertisement
eN-t

BAT Tips & Tricks

May 9th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. title Trickkiste
  3. setlocal EnableDelayedExpansion
  4. color 07
  5. mode con:cols=105 lines=35
  6.  
  7.  
  8.  
  9. :init
  10. REM Initialize...
  11.  
  12. REM Enable colored echo (header)...
  13. for /F "tokens=1 delims=#" %%i in ('"prompt $H# & for %%i in (1) do rem"') do (
  14.     set DEL="%%i"
  15.     )
  16.  
  17.  
  18.  
  19. echo.
  20. call :echocol "0C" "this is red"
  21. echo.
  22. call :echocol "0E" "this is yellow"
  23. echo.
  24. call :echocol "0A" "this is green"
  25. echo.
  26. call :echocol "09" "this is blue"
  27. echo.
  28. echo Initializing...
  29. call :progbar "500"
  30. echo.
  31. echo Checking connection...
  32. call :progbar "50"
  33. echo.
  34. call :spechar "test $E this was test"
  35. echo.
  36. call :spechar "$L$G$C$F$A$E"
  37. echo.
  38. call :setdelay "variable" "Bitte treffen Sie Ihre Eingabe" "30"
  39. echo Ihre Eingabe war: "%variable%"
  40. echo.
  41. call :setdelay "variable" "Bitte treffen Sie eine andere Eingabe, diese war ungueltig" "58"
  42. echo Ihre Eingabe war: "%variable%"
  43. echo.
  44. call :echodelay "WICHTIG: Lassen Sie niemals Ihren PC unbeaufsichtigt - ein unbeaufsichtigter PC stellt eine Gefahr dar." "103"
  45. echo.
  46. call :echodelay "counting one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteenseventeen eighteen nineteen twenty twenty-one twenty-two ..." "165"
  47. echo.
  48. echo.
  49. echo                 
  50. pause
  51. goto :eof
  52.  
  53.  
  54.  
  55. :echocol
  56. REM Enable colored echo (footer)...
  57. REM Usage: call :echocol "XY" "TEXT"
  58. REM  where "XY" is the colorcode
  59. REM  where "TEXT" is the text (no special chars)
  60. cd /D %TEMP%
  61. <nul set /P .=%DEL%>"%~2"
  62. findstr /V /A:%~1 /R "nul" "%~2" nul
  63. del /F /Q "%~2">nul
  64. cd /D "%~dp0"
  65. goto :eof
  66.  
  67. :echodelay
  68. REM Enable echo delayed...
  69. REM Usage: call :echodelay "TEXT" "LENGTH"
  70. REM  where "TEXT" is the text of the string
  71. REM  where "LENGTH" is the length of the string
  72. echo wscript.sleep "30">"%TEMP%\sleep.vbs"
  73. for /L %%i in (0,1,%~2) do (
  74.     set tempstring=%~1
  75.     if /I "!tempstring:~%%i,2!"=="!tempstring:~%%i,1! " (
  76.         set /P %~1="!tempstring:~%%i,1! "<nul
  77.     ) else (
  78.         set /P %~1="!tempstring:~%%i,1!"<nul
  79.     )
  80.     wscript "%TEMP%\sleep.vbs"
  81. )
  82. del /F /Q "%TEMP%\sleep.vbs">nul
  83. echo.
  84. goto :eof
  85.  
  86. :setdelay
  87. REM Enable set variable with shown example delayed...
  88. REM Usage: call :setdelay "VAR" "TEXT" "LENGTH"
  89. REM  where "VAR" is the name of the variable
  90. REM  where "TEXT" is the text of the string
  91. REM  where "LENGTH" is the length of the string
  92. echo wscript.sleep "50">"%TEMP%\sleep.vbs"
  93. for /L %%i in (0,1,%~3) do (
  94.     set %~1_sub=%~2
  95.     if /I "%%i"=="%~3" (
  96.         set /P %~1=": "
  97.     ) else (
  98.         if /I "!%~1_sub:~%%i,2!"=="!%~1_sub:~%%i,1! " (
  99.             set /P %~1="!%~1_sub:~%%i,1! "<nul
  100.         ) else (
  101.             set /P %~1="!%~1_sub:~%%i,1!"<nul
  102.         )
  103.     )
  104.     wscript "%TEMP%\sleep.vbs"
  105. )
  106. del /F /Q "%TEMP%\sleep.vbs">nul
  107. goto :eof
  108.  
  109. :progbar
  110. REM Enable progress bar...
  111. REM Usage: call :progbar "X"
  112. REM  where "X" is the sleep-amount per percent in milliseconds
  113. echo wscript.sleep "%~1">"%TEMP%\sleep.vbs"
  114. for /L %%i in (1,1,10) do (
  115.     if /I "%%i"=="10" (
  116.         set /P progbar="±±±±±±±±±° 100%%"<nul
  117.     ) else (
  118.         set /P progbar="±±±±±±±±±°"<nul
  119.     )
  120.     wscript "%TEMP%\sleep.vbs"
  121. )
  122. del /F /Q "%TEMP%\sleep.vbs">nul
  123. goto :eof
  124.  
  125. :spechar
  126. REM Enable special characters...
  127. REM Usage: call :spechar "X"
  128. REM  where "X" is your string with several character codes from A-Z and 0-9 with $ in front of, e.g. "test $E this was test"
  129. for /F "tokens=1 delims=#" %%i in ('"prompt %~1# & for %%i in (1) do rem"') do (
  130.     echo %%i
  131. )
  132. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement