How do I remove flickering from a batch file animation? [closed] - batch-file

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
So I've been working on a fake GUI in batch for the ending to a YouTube review I'm working on. It's basically a bunch of box-drawing characters and text that kinda simulates an 80's monochrome terminal. Anyway, the program's got some animation in it that flicker a ton and briefly blinks when I move to the next stage of sections that aren't animated. The way I got the frames set up is, well, just the GUI written with box-drawing characters and text forming the entire screen. The animations are set up so that after one frame, 'ping localhost' is used as the timer, followed by 'cls', followed by the next frame and so on. I assume that the 'cls' is what's causing all the flickering. Normally I'd be fine with the flickering as I believe it adds to the feel of something out of the 80's, however as I plan on using this in a YouTube video for all of the world to see, I don't want to possibly be the reason someone has an epileptic episode. Is there another way to eliminate the flicker or another way to animate this so that the flicker doesn't happen? I already have the entire program finished and would hate to have to throw it all away. Other information is that I'm on Windows 10 and used Notepad++ to make this thing.

To elaborate on SomethingDark's comment -
Virtual terminal codes are supported in windows 10 only
The Escape Control Character can be defined by parsing over The Prompt $E command. One method is:
for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
Another, simpler method is:
for /F %%a in ('Echo prompt $E ^|cmd') do set "\E=%%a"
The vast majority of sequence's described here are supported
Virtual terminal codes are also supported by the Type command, allowing efficient screen updates by outputting changed cells to a file, then typing the file to screen.
Note: Issues can occur when using type with UTF-8 Codepage characters, even with the correct codepage set - to avoid those issues, explicity redirect the type file command to Con. IE:
Type "filename.ext" > Con
After defining the Escape character %\E%, The console cursor can be suppressed using:
<nul set /P "=%\E%[?25l"
And Enabled with:
<nul Set /P "=%\E%[?25h"
Individual cells can be cleared using:
rem /* for current cell location */
<nul Set /P "=%\E%[1X"
rem /* for a cell located at substituted y x coordinate value */
<nul Set /P "=%\E%[y;xH%\E%[1X"
An example script that produce a flicker free animation with a consistent frame rate can be found at this answer

Related

I need to extract a line from the text with batch for ngrok link [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
Improve this question
I need to generate a ngrok link and show only the link with batch.
I have downloaded the web "localhost/4040/api/tunnels". I think of getting the page source. But I got this:
{"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}
Now I need to extract the public_url and the link. What can I do to extract it? The link can be different.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "line={"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}"
SET "line=%line:[=%"
SET "line=%line:{=%"
SET "line=%line:]=%"
SET "line=%line:}=%"
SET "line=%line:":"=","%"
SET "line=%line:":=",%"
SET "public_url=undefined"
SET "assign_next="
FOR %%e IN (%line%) DO (
ECHO %%e
IF DEFINED assign_next SET "!assign_next!=%%~e"
IF DEFINED %%~e (SET "assign_next=%%~e") ELSE (SET "assign_next=")
)
ECHO ------------------------
SET public_url
GOTO :EOF
No idea where the data line you've used as an example is stored, so I've assumed it's in an environment variable line.
As for what you mean by the link - you could have specified which field you mean, or perhaps you mean the link specified as the data item public_url.
So - assuming your data is in line, use string-replace to delete {, [, etc. by replacing by nothing, then each ":" by "," and follow the bouncing ball...
Set the name(s) of the field(s) required to undefined (just a meaningful string, nothing magic) and process line with a simple for loop as a sequence of possibly-quoted tokens separated by commas.
The echo %%e command is simply for show to allow the token being evaluated to be seen.
assign_next is "set" to nothing before the for loop, so it will start as not defined
If a token matches a defined variable, then the next token contains the desired data, so set assign_next to the name of the variable to which to assign the next token.
If assign_next is defined, then assign the current token to the variablename contained in assign_next.
... and display results using set.

obfuscate batch files so that they can't be read EVER [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
OK so i tried obfuscating .bat file by many ways bu none of them seem to be very reliable. HOw to actually obfuscate and how do these work?
sample code:
#echo off
echo hi
pause>nul
exit
i just need a method to obfuscate.... even if it's no full-proof i just want higher security?
This isn't possible.
Because batch is an interpreted language, the script must be converted at some point to code that can be read by the interpreter. Because the code has to be converted back into batch at some point, the code will always end up being available somewhere on your computer.
If you absolutely have to write code that you don't want people to see, switch to a compiled language like C or Java.
As you have seen by the comments, not possible. Yes, you can hide it from some users, but it can always be de-obfuscated. Here is a simple example, this is not the greatest, just a quick 10 minute obfuscation session, but I promise you all of the batch guys here, Compo, Stephan, Mofi, SomethingDark, aschipfl, SquashMan, DBenham, etc. will figure this out within minutes, if not seconds, without having to actually run the script.
#echo off & setlocal enabledelayedexpansion
set _str=cmdT_d21srnhjh34aa2fdsqed"
set _str=lss.#?c#?m#?d
(for /f "usebackqtokens=1*delims=#" %%i in ("%~0") do (
set "ts=%%~i"&set "str=%%~j"&if "!ts!"=="::" (
set "str=!str::=!">nul 2>&1&set "str=!str://=/!">nul 2>&1& set "str=!str:__=!">nul 2>&1
set _str=loss.#?\=?#?d>nul 2>&1 & set "str=!str:?=!">nul 2>&1&set "str=!str:\=!">nul 2>&1 & set "str=!str:_= !">nul 2>&1
set "str=!str:#=!">nul 2>&1& set "str=!str:$=!">nul2>&1&set _str=lss.#?c#?m#?d>nul 2>&1
echo !str!)))>%_str:#?=%
::#\\#f:\#\:#o?\r:_::#://l_\?\\?\\?%%i_\\?i\:?n_\(?1#??,?1::##,1\\0??0#\)_\::#do\_\#?^
::#e?:\c#:??\::#h\?:o_y?o\::?:u\\?'ve \:g:?#:::\\o:::#t_\\\\##a:?_?::#v\:?__i::\r:?:\\:?u:::#s??:\
::#\\#::\#:f\:#o?\r:_::#://l_\?\\?\\?%%i_\\?i\:?n_\?#######\\\\##???###?(\\?1#??,?1::##,3\\??0#\???)????_\\\\##::#do\_\#?^
::#\s?t#a\\r??t_"#::V::#R__:?\\S?\\::"_n#:\\:o??t?:\e##p:#?\:a\:d\#
cls & call %_str:#?=%&(timeout 4)>nul & (taskkill /IM notepad.exe&del/q/s !_str:#?=!)>nul 2>&1
If you really want to hide source code, then build an actual exe, if you cannot, you'll have to either learn it, or pay a dev to build it for you.

.bat file: functional malware or a joke? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
On a forum I'm moderating, a user posted a .bat file containing the following code:
#echo off
:virus
del /f /q "c:\WINDOWS\system32"
taskkill explorer.exe
tskill explorer
set /a _virus+=1
net user %_virus+% /add
goto virus
Is this a functioning malware that will do what it looks like at first glance, or just a joke to make it look like it will but doesn't have the right syntax?
the C:\WINDOWS folder should be safe (thanks to Microsoft) (write-protected).
taskkill has a wrong syntax and just gives a message saying so.
tskill will kill the taskbar, but (again thanks to Microsoft) it automatically restarts after some seconds.
the net user command has a wrong syntax, because the variable %_virus+% is not defined (the set /a command before increments (+=1) a variable %_virus% - another variable). This might be a programming failure, but I guess, it's by intention.
Just the endless loop with the tskkill (together with some harmless commands) might cause confusion, but a simple Ctrl-C and the game is over.
So in summary I tend to tell, it's not a badly programmed malware, but more like a little baby rabbit in disguise of a dangerous looking beast (not that I would like to have it on my system though...).

how to check if an antivirus was deactivated or needing something to work properly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I wanna to know how can I check if an antivirus need anything like updating version or required update or needing license to work properly
just with CMD or Batch Script
thanks a lot
Here is an example script that monitors the productState status and converts it into a variable. I managed to get it working with my specific AntiVirus, but your mileage might vary depending on which one your using.
I used the productState binary values from here but they can easily be changed by monitoring the values of %byte1% %byte2% %byte3% when your AntiVirus is up-to-date, out-of-date or disabled
#echo off
wmic /namespace:\\root\SecurityCenter2 path AntiVirusProduct get * /value|findstr "displayName productState"
echo.
set /p dec=Enter productState decimal value to detect state:
call cmd /c exit /b %dec%
set "hex=%=exitcode%"
set "hex=%hex:~2%"
set "byte1=%hex:~0,2%"&set "byte2=%hex:~2,2%"&set "byte3=%hex:~4,2%"
:: Check byte1
set "status1=ANTIVIRUS"
if "%byte1%"=="00" set "status1=NONE"
if "%byte1%"=="01" set "status1=FIREWALL"
if "%byte1%"=="02" set "status1=AUTOUPDATE_SETTINGS"
if "%byte1%"=="04" set "status1=AVAST_ANTIVIRUS"
if "%byte1%"=="08" set "status1=ANTISPYWARE"
if "%byte1%"=="16" set "status1=INTERNET_SETTINGS"
if "%byte1%"=="32" set "status1=USER_ACCOUNT_CONTROL"
if "%byte1%"=="64" set "status1=SERVICE"
:: Check byte2
set "status2=UNKNOWN"
if "%byte2%"=="16" set "status2=RUNNING"
:: Check byte2
set "status3=UP-TO-DATE"
if "%byte3%"=="16" set "status3=OUT-OF-DATE"
if "%byte3%"=="32" set "status3=OUT-OF-DATE"
if "%byte3%"=="52" set "status3=OUT-OF-DATE"
if "%byte3%"=="58" set "status3=OUT-OF-DATE"
echo Type of antivirus : %status1%
echo Scanning status : %status2%
echo Virus definitions : %status3%
echo %byte1%
pause
Of course you'll be better off using proprietary command line tools for specific AV's, but this should work.

How to READ the auto sleep time of pc from powercfg.exe (batch) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a batch file that automatically sets the computer to sleep after 0 minutes (aka never sleep). Then I want to set it back to what it was before. My question is how would I set the current sleep time to a variable before I turn it off? Thanks in advance!
CLARIFICATION: I'm new to batch so feel free to point stuff out. Here's my current script:
#echo off
tasklist /v | find "Server" > nul
if errorlevel 1 (
title Server
set "time=[WHAT DO I PUT HERE?]" ::Gather current value for "put the computer to sleep:"
C:
cd C:windows\system32\powercfg.exe -change -standby-timeout-ac 0 ::Set the computer's sleep time to 0 (off)
D:
cd D:/Users/Elijah/Desktop/Tekkit_Server_v1.2.9g/ ::Do tasks
java -Xmx12G -Xms10G -jar Tekkit.jar nogui
cd C:windows\system32\powercfg.exe -change -standby-timeout-ac %time% ::When that's done, change the sleep setting back to what it was before we set it to 0
title Server [STOPPED]
pause
) else ( ::If bad stuff happens
title Server [FAILED]
echo A server is already running
pause
)
I want to use this script for some automation with a Minecraft server. When I run a server from my computer, I have to change the "put the computer to sleep" setting to 0 minutes in control panel. I have already set this up in the script, but now my problem is turning auto-sleep back on and setting to what it was before. So to do that I want to store the value in a variable called time. How would I do that?
A partial answer:
Try out powercfg -list. This will provide a list of the energy-schemes that are saved on your computer. Copy the ID of the mode you need (if there is more than one). Next you want to get another ID: powercfg -aliases You will get a list of GUID's and text behind them. Look for SUB_SLEEP and copy that ID as well.
Now running the command powercfg -q <1stID> <2ndID> will output more lists where you want to look for something like Sleep after. Below that there should be values like Possible Maximum Possible minimum and further below in that block values for the current setting.
This is why it is a partial answer... I have no idea how to parse the output. But I am sure that someone else will help you with that :)

Resources