Having trouble with color code in batch file - batch-file

I'm trying to only have ffmpeg progress to be colored, but for some reason when I terminate or go full-screen this monstrosity occurs:
Issue
#echo off
#echo off
title Stream Recorder
cls
:start
set message=Stream Recorder
echo %message%
echo(
echo [32m1. Chrome [0m
echo [34m2. Edge [0m
echo [33m3. Firefox [0m
echo [31m4. Opera [0m
echo [1;31m5. Vivaldi [0m
:choice
set choice=
set /p "choice=* Pick your browser (between 1-5): "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto chrome
echo "%choice%" is not valid, try again.
ECHO.
goto choice
:chrome
:url
echo(
set /p "address=* M3U8 Url: "
For /F %%G In ('%__AppDir__%curl.exe -s -o NUL "%address%" -w "%%{http_code}\n"') Do Set "response=%%G"
echo %response%
IF %response% == 200 (
ECHO [32mURL check was successful.[m &goto :username
) ELSE (
ECHO [31mURL is not valid, try again.[m &goto :url
)
:username
set /p "filename=* Streamer Name: "
echo(
set message=* Recording:
echo [0m%message%[42;1m
ffmpeg -v warning -hide_banner -stats -user_agent "" -i "%address%" -c copy "%~dp0/%filename%_%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%time:~-11,2%-%time:~-8,2%-%time:~-5,2%.mp4"
pause
Also, would be helpful if my code needs some cleaning up.

That last echo is the problem:
echo Escape[0m%message%Escape[42;1m
The first Escape chunk turns off color and bold, while the second turns color and bold on.
To fix the problem, you need (at least)
echo Escape[0m
before the pause. But that may not be enough, because ffmpeg is printing to the terminal (presumably) without modifying colors. If it happens to clear the current line or to the end of the display, most terminals (supporting back color erase) will fill the cleared area with the current color.
Perhaps you don't want ffmpeg to have that opportunity.

Related

Incorrect syntax when asking for user input

I am trying to make a quick program in Batch that asks for user input, but when i get to the input part, the script exits with error:
The syntax of the command is incorrect.
This is my code:
#echo off
color 0a
title WinDoS/PoD- 0.1
echo Automatic DoS/PoD Tool
echo Select what you want to do.
echo 1. Attack
echo 2. Instructions
echo 3. IP Getter
echo 4. IP Searcher
echo 5. Exit
set /p userchoice=
if %userchoice% == 1
goto attack
if %userchoice% == 2
goto instructions
if %userchoice% == 3
goto getter
if %userchoice% == 4
goto searcher
if %userchoice% == 5
exit
:searcher
arp -a
pause
:attack
echo Enter IP adress to attack
set /p address=
goto sequence
:sequence
ping %address% -l 65500 -w 1 -n 1
goto sequence
:instructions
echo WinDoS/PoD Instructions
echo WinDoS/PoD is a program that allows you to perform Denial Of Service (DoS) attacks using a method known as Ping Of Death (PoD)
echo Press 1 on the home menu to enter the attacker program.
echo Input an ip address to DoS
echo If you don't know the IP address to a site, use the built in getter.
echo If you want to view all available network targets, use the built in searcher.
pause
:getter
echo Website (full link):
set /p %website%=
tracert %website%
pause
What is wrong with the syntax?
You're using the wrong command for choosing a known list item, you should be using choice, not set.
Here's an example using your provided information as its basis:
#Echo Off
Color 0A
Title WinDoS/PoD- 0.1
:Menu
Echo(
Echo Automatic DoS/PoD Tool
Echo(
Echo Home Menu
Echo(
Echo 1. Attack
Echo 2. Instructions
Echo 3. IP Getter
Echo 4. IP Searcher
Echo 5. Exit
Echo(
%__AppDir__%choice.exe /C 12345 /N /M "Select a Home Menu item number>"
If ErrorLevel 5 GoTo :EOF
If ErrorLevel 4 GoTo Searcher
If ErrorLevel 3 GoTo Getter
If ErrorLevel 2 GoTo Instructions
:Attack
ClS
Set /P "address=Enter IP address to attack> "
:Sequence
%__AppDir__%ping.exe %address% -l 65500 -w 1 -n 1
GoTo Sequence
:Instructions
ClS
Echo WinDoS/PoD Instructions
Echo(
Echo This program allows you to perform Denial Of Service (DoS) attacks,
Echo using a method known as Ping Of Death (PoD).
Echo(
Echo Press 1 on the Home Menu to begin the Attack program.
Echo Input an IP address to DoS
Echo If you don't know the IP address for a site, use the built-in Getter.
Echo If you want to view all available network targets, use the built-in Searcher.
Echo(
Pause
GoTo Menu
:Getter
ClS
Set /P "website=Website (full link)> "
%__AppDir__%tracert.exe %website%
Pause
GoTo Menu
:Searcher
ClS
%__AppDir__%arp.exe -a
Pause
GoTo Menu
Please note, that I have not looked at the usage of any of your commands, I have offered only improvements to the layout and functionality.

Batch counter program shutting down

So I am making a counter and I am not sure how to make it work.. I have this right now with some other functions for customization purposes:
set /a current_value=current_value+incremental_value
but it does not work unfortunately..
The whole purpose is to use the pause >nul function so when ever the user presses a key then the screen will show a number go up by the incremental value chosen earlier..
This is the whole script:
#echo off
cls
title Counter
:Incremental_Value
cls
echo./----------------------------------------------\
echo.I Set the Incremental Value then press Enter I
echo.\----------------------------------------------/
echo.
set /p %incremental_value%= [
:Starter_Value
cls
set current_value=%starter_value%
echo./------------------------------------------\
echo.I Set the Starter Value then press Enter I
echo.\------------------------------------------/
echo.
set /p %starter_value%= [
goto Counter
:Counter
cls
echo./-------------------\
echo.I %current_value% I
echo.\-------------------/
echo.
pause >nul
set /a current_value=current_value+incremental_value
goto Counter
Edit: I fixed the shutting down problem, but when you first get to the Counter screen the number does not appear. Once you hit a key it becomes zero (if you set the starting value to zero) then it wont add the incremental value if you continue to press the key.
A very simple issue you had was the improper use of the set /p command. When using set /p, you do not specify the string as set /p %String%= but rather set /p String=. For more information on the set command try typing set /? into a command prompt.
Another issue, not problem is that you have :Incremental_Value & :Starter_Value but you never call or goto them in the script. The only place you properly did this was with goto Counter. Unless you are going to individually goto/call them later, just remove them; or use goto :Starter_Value - exc.
In the future, try using echo( instead of echo. to call a blank space in the window.
Counter.bat
#echo off
title Counter With Incremental Progression
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Set the Starter Value then press Enter º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo(
set /p starter_value=Value:
cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Set the Incremental Value then press Enter º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo(
set /p incremental_value=Value:
Set "current_value=%starter_value%"
:Counter
cls
echo Current Number: %current_value%
echo(
pause >nul
set /a "current_value=current_value+incremental_value"
goto Counter
PS: Switch the file encoding to ANSI for fun boxes - :-)

creating image with batch >>%cd%

i would like to see if its possible to echo to an image like you can echo to a file:
echo Hello World! >>"%cd%/test.txt
Like this:
echo (base64 code) >>"%cd%/image.jpg"
what is even wrong with this?
it creates a jpeg file but it gives me the error that it can't be opened.
(probably of its code structure)
I checked it with the base64 to image converter and there is nothing wrong.
Why doesn't it create an image?
This batch file Certutil_B64_Encoding_Files.bat can let you to drag and drop any file like a jpg or png or any file else and generate another batch file with the encoded file inside, So, when you execute it, the file will be decoded and generated to the original.
Just save this code on your notepad or on notepad++ or on any text editor as :
Certutil_B64_Encoding_Files.bat and drag and drop any file over it to be encoded
#echo off
Title Encoding files with CERTUTIL utility by Hackoo 2018
color 0A & Mode 83,3
If "%~1"=="" (
color 0C & Mode 80,3
echo(
echo You must drag and drop a file over this batch script to be encoded !
Timeout /T 5 /nobreak>nul & exit /b
)
#for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
set "TempFile=%Temp%\Temp_b64
set "OutputFile=%~nx1_encoded%~x0"
If exist "%OutputFile%" Del "%OutputFile%" >nul 2>&1
echo(
echo Please wait a while ... Encoding "%~nx1" is in progress ...
certutil.exe -f -encode "%~1" "%TempFile%" >nul 2>&1
(
echo #echo off
echo Title My head kinda look like this
echo echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo echo and my head kinda look like this:
echo CERTUTIL -f -decode "%%~f0" "%%Temp%%\%~nx1" ^>nul 2^>^&1
echo Timeout /T 5 /nobreak^>nul
echo Start "%~n1" "%%Temp%%\%~nx1"
echo Exit
)>> "%OutputFile%"
copy "%OutputFile%" /b + "%TempFile%" /b >nul 2>&1
If exist "%TempFile%" Del "%TempFile%" >nul 2>&1
Timeout /T 2 /NoBreak>nul & exit
And here is an example that i tested with my avatar Hackoo.png
Hackoo.png_encoded.bat
#echo off
Title My head kinda look like this
echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo and my head kinda look like this:
CERTUTIL -f -decode "%~f0" "%Temp%\Hackoo.png" >nul 2>&1
Timeout /T 5 /nobreak>nul
Start "Hackoo" "%Temp%\Hackoo.png"
Exit
-----BEGIN CERTIFICATE-----
/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1
c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMD
BAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgW
FBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAQABAAwEiAAIRAQMRAf/E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQE
AAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBka
JSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SF
hoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY
2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgME
BQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKB
CBRCkaGxwQkjM1LwFWJy0QoWJDTh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Windows CMD command line - An excellent reference for all things Windows cmd line related.
certutil - Dump and display certification authority (CA) configuration information, configure Certificate Services, back up and restore CA components, verify certificates, key pairs or certificate chains.
You can use the command HEX2PNG.EXE to reconstruct a text file to an image.
Example :
smiley.txt
--------------#####--------------
-----------###.....###-----------
---------##...........##---------
-------##...............##-------
------#...................#------
-----#.....................#-----
----#...####........#####...#----
----#..####c#......####cc#..#----
---#..#####cc#....#####ccc#..#---
---#..#####cc#....#####ccc#..#---
--#...####ccc#....####cccc#...#--
--#..#cccccccc#..#ccccccccc#..#--
--#..#cccccccc#..#ccccccccc#..#--
-#...#cccccccc#..#ccccccccc#...#-
-#...##########..###########...#-
-#.............................#-
-#.............................#-
-#.............................#-
--#..#######################..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
---#..#aaaaaaaaaaaaaaaaaaa#..#---
---#..#aaaaaaaaaaa;;;;aaaa#..#---
----#..#aaaaaaaaa;;;;;;aa#..#----
----#...#aaaaaaa;;;;;;;;#...#----
-----#...##aaaa;;;;;;;##...#-----
------#....###;;;;;###....#------
-------##.....#####.....##-------
---------##...........##---------
-----------###.....###-----------
--------------#####--------------
To build the image you have to replace each kind of char with an hexa color and then run hex2png.exe against the smileuout.txt :
In this case
The char [c] with white [FFFFFFFF]
The char [a] with maroon [103E66FF]
The char [.] with yellow [00EAFFFF]
The char [-] with transparent (black + transparent value to 00) [00000000]
The char [#] with black (non transparent) [000000FF]
The char [;] with red [0000FFFF]
This bat will do that :
#echo off
set $fichier=smiley.txt
set $taille=33;31
set $TotPix=1023
set $Fsortie=smiley.png
:::Crátion de la première ligne de sortie.txt (width_pixel;Height_pixel;Name_of_file.PNG;Total_number_of_pixel)
echo %$taille%;%$Fsortie%;%$TotPix%>SmileyOut.txt
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type %$fichier%') do (echo %%a
set $ligne=%%a
set $ligne=!$ligne:c=FFFFFFFF !
set $ligne=!$ligne:a=103E66FF !
set $ligne=!$ligne:.=00EAFFFF !
set $ligne=!$ligne:-=00000000 !
set $ligne=!$ligne:#=000000FF !
set $ligne=!$ligne:;=0000FFFF !
set /a $c+=1
for %%b in (!$ligne!) do (echo %%b>>SmileyOut.txt))
endlocal
hex2pngV1.3.exe smileyout.txt
del smileyout2>nul
start smiley.png
The output will be this nice smiley :
The structure of the file smiley.txt is very important !
This vars must be setted correctly or the image will be corrupted :
$fichier=smiley.txt
$taille=33;31 => width;height of the output file each char is one pixel
$TotPix=1023 => The total of pixel (width * height)
$Fsortie=smiley.png => the name of the output PNG
The command PNG2HEX will do exactly the contrary an generate a txt file from an image !

bat file Error "invalid verb switch" when using wmic

Hey guys i need some help i am a total noob to bat files i am getting this error "invalid verb switch" I dont understand why?
All i am wanting to do is rename the current user with %newusername%
I have looked on line and everything seams to be the same any thoughts?
#echo off
for /F "tokens=4 delims=.:" %%G in (
'ping -4 %COMPUTERNAME%^|find "Reply from"'
) do set "IP=%%G"
set "ipadd=%IP:~-3%"
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
set /p pathName=Employees Name:%=%
set /p store=Store prefix (ie: rfl, rac, rca, rdcjr):%=%
set /p location=location (ie: salesflrN1, partsNE2):%=%
echo.
echo.
echo ip address: %last3digits%
set newusername=%store%.%ipadd%-%pathName%
echo New User Name Will Be: %newusername%
echo.
echo ___________________________________________________________________________
echo ***************************************************************************
echo ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
echo.
echo By Pressing enter you will be performing the following actions....
echo.
echo 1. Updating The computers name to: *******
echo 2. Updating The computers User Name to: *******
echo 3. And You Will Be Forceing A System Reboot: *******
echo.
echo 3. Press "Enter" To Continew Or Alt+F4 To Exit
echo.
echo ___________________________________________________________________________
echo ***************************************************************************
echo ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
pause
wmic useraccount where name='%username%' rename %newusername%
pause
This ended up fixing my error:
wmic useraccount where name='%USERNAME%' call rename name='%newusername%'
net.exe user "%newusername%" /fullname:"%newusername%"
Looks like I was missing the call and name= option.

Using If Statements in Batch Files

I have a script of batch (modeled after Joshua in "War Games")
#echo off
color 0b
echo Greetings, Professor Falken
set /p interface =
echo Would You Like to Play a Game?
set /p ifGame =
if /i "%ifGame%" =="yes" goto yesgame
if /i "%ifGame%" =="no" goto nogame
:yesgame
echo List of Games
echo chess
echo Poker
echo Fighter Combat
echo Guerilla Warfare
echo Desert Warfare
echo Air-to-Ground Actions
echo Theaterwide Tactical Warfare
echo Theaterwide Biotoxic and Chemical Warfare
echo Global Thermonuclear War
pause
echo Which game would you like to play?
set /p WhichGame =
pause
exit
:nogame
set /p areYouSure=Are You Sure?
pause
exit
But, when I enter "No" it still shows the list of games...
You need to remove the spaces between the variable name and the = symbol when using set /p. From:
set /p ifGame =
To:
set /p ifGame=
Otherwise the variable you set has a space at the end of the name. So %ifGame% expands to nothing, whereas %ifGame % will expand to the correct value.

Resources