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 8 years ago.
Improve this question
I have a problem with understanding a batch file that is a part of a task (sort of hackme).
I find it hard to find informations about it in google, i dont know, i feel like there isnt any good batch language documentation or soemthing other that is solid.
my first question, what it does? It is possible to dont satisfy the condition ?
if not "!"=="" (
echo Authorization failed!
pause>nul
exit
)
Secound question, what this kind of IF's does ?:
set %1.pass=%2
if "!%1.pass:~5,1!"=="" (
.....
if not "!%1.pass:~6,1!"=="" (
Thank you,
#EDIT
technet.microsoft.com/en-us/library/cc754340(v=ws.10).aspx
i have read it, it doesnt answer my questions
You might check it out by yourself:
#echo off &SETLOCAL
if not "!"=="" (ECHO NOT equal) ELSE ECHO equal
SETLOCAL ENABLEDELAYEDEXPANSION
if not "!"=="" (ECHO NOT equal) ELSE ECHO equal
SET "property.pass=ABCDE"
ECHO %property.pass:~0,1% %property.pass:~1,1% %property.pass:~2,1% %property.pass:~3,1%
Output is:
NOT equal
equal
A B C D
Related
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 1 year ago.
Improve this question
What does this piece of code means? Could someone explain it to me?
set "txt=!txt:~0,-1!"
#echo off
setlocal EnableDelayedExpansion
set "txt="
set input=input.txt
for /f "delims=" %%a in (%input%) do (
set "txt=!txt!%%a,"
)
set "txt=!txt:~0,-1!"
>new.txt echo !txt!
This code returns a substring of the contents of the variable txt.
The two numbers indicate the start and end location of the requested substring in the original value of variable txt.
A negative value for the second number means count backwards.
So in your example the returned value will be the contents of variable txt without the last character.
For more info on this syntax see:
https://ss64.com/nt/syntax-substring.html
It does mean: 'cut last character from variable !txt!'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a program that creates .bat files to c:\temp.
I need to create a script that runs each .bat file inside c:\temp and moves them to c:\temp\backup after a successful execution.
How can i achieve this?
Thank you
The following code can be a good starting point.
Use the for loop to enumerate the files with .bat extension in the given directory.
Use the call command to execute.
Use the move command to move the file to other directory.
Update: As suggested in the comments, I added a basic error checking if the call command succeeded and only in the case of success, I am moving the bat file.
#echo off
set myDir=C:\temp\bats
set doneDir=C:\temp\bats\done\
md %doneDir%
for %%I in ("%myDir%\*.bat") do (
call %%I
if %ERRORLEVEL% == 1 (
move %%I %doneDir%
) else (
echo "error moving - %errorlevel%"
)
)
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.
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 4 years ago.
Improve this question
I'm trying to make a batch file that will read a text file (Net.txt) to pull a datapath from it. Assign it to a variable then empty a file from a nearby location.
Net.txt looks like
SharedPath=C:\Program\2017\
SharedUNC=C:\Program\2017\
Then find the directory and delete files with a specific extension.
cd %variable%\OPTION\trash
DEL *.xxx
This works great locally when everything is on C: but I don't think batch/cmd supports UNC paths. Is there a better language to use?
To read a file line by line, use a for /f loop.
The following code assumes net.txt to be exactly as shown in your question and will delete the files in both the SharedPath and the SharedUNC (should they differ; if they are the same, del will spit an error for the second one (which you can suppress with 2>nul))
for /f "tokens=2 delims==" %%a in (net.txt) do del "%%aOPTION\trash\*.xxx"
If that is not what you want, please describe your problem in more detail.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have two numeral values, %Points%, and %PCP1%.
I wish to have something like:
IF (%Points% < %PCP1%) (
cls
echo Not enough money!
echo Hit enter to return home
pause
goto 2
)
ELSE (
echo Confirm Purchase? Your Points after this purchase will be (%Points% - %PCP1%)
pause
)
It doesn't work. Please help. Thanks!
The less than operator is LSS i.e.:
IF (%Points% LSS %PCP1%) (
Other Operators are:
EQU: equal to
NEQ: not equal to
LSS: less than
LEQ: less than or equal to
GTR: greater than
GEQ: greater than or equal to