Caml Light

CMD: OPTION to jump

33 posts in this topic

Hi guys! If my batch file contains this:

:Sorry

ECHO Sorry!

:Welcome

ECHO Welcome!

Is it possible to jump to the ":Sorry" label if i open the cmd file and to jump to the ":Welcome" label if i open the same cmd file followed by an option (for example: batch.cmd /jump)?

Thank you!!

0

Share this post


Link to post
Share on other sites

goto %1

:sorry
Echo Sorry!
Goto :end

:welcome
echo welcome
Goto :end

:end

just use the label name for the switch

0

Share this post


Link to post
Share on other sites

a last question... if i convert my CMD batch to EXE, for a person that doesn't know the label i've given, is it possible to jump directly to the "Welcome" label, or anyway to find it's name? I'd to protect my batch file.. so do you think it's a secure solution? Thanks! :hello:

Edited by Caml Light
0

Share this post


Link to post
Share on other sites

It just depends on how secure you want it to be: if you use a batch to exe converter, most of them will only unpack the batch in a temporary folder and run it from there and then the protection will be very light.

0

Share this post


Link to post
Share on other sites

..and what do you suggest me to protect better my cmd script? Thanks in advance!

0

Share this post


Link to post
Share on other sites

Make it into a autoit file and compile it with password...

0

Share this post


Link to post
Share on other sites

Make it into a autoit file and compile it with password...

....and make it longer than 12 characters and make sure you insert "strange" non alpha-numeric characters and not a-z/A-Z ones.

Examples:

  • h1_1_@m_@_|33t_p@§§vv0rd
  • ÿ00_vv0n*t_cr@ç#-m3

:angel

BTW, IcemanND's nice batch may be "bettered" (assuming you are on a 2K/XP or later NT based system):

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
IF NOT "%1"=="" FOR /F %%A in ('type %~nx0 ^|FIND ":%1" ^| FIND /V "FIND"') DO GOTO :%1
Echo A suffusion of yellow ...
GOTO :EOF

:sorry
Echo Sorry!
GOTO :EOF

:welcome
echo welcome

OR (to follow your original post):

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
IF NOT "%1"=="" FOR /F %%A in ('type %~nx0 ^|FIND ":%1" ^| FIND /V "FIND"') DO GOTO :%1
Echo Sorry!
GOTO :EOF
:welcome
echo welcome

OR:

@ECHO OFF
SETLOCAL
IF /I "%1"=="welcome" GOTO :%1
Echo Sorry!
GOTO :EOF
:welcome
echo welcome

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

•h1_1_@m_@_|33t_p@§§vv0rd

•ÿ00_vv0n*t_cr@ç#-m3

OMG LOLZ

0

Share this post


Link to post
Share on other sites

You can use an obfuscator (some batch to exe do this but most of them aren't free) or use another language like autoit (which is a little more secure when using a password ).

You could also change the code to make it so complex that just reading it would not help "the man in the middle" to understand it.

Edited by allen2
0

Share this post


Link to post
Share on other sites

IIRC, the password in AutoIT is only for their decompiler that is meant for AutoIT v2 executables. It was this entire purpose (they lock topics over there if you ask about it) that this function was removed in v3, although you can still put a password in it. But this password does nothing for other decompilers.

0

Share this post


Link to post
Share on other sites

thank you for your reply guys! I want to specify that to protect my batch i can't use any password to type in.

To convert to EXE my batch i've used "Bat To Exe Converter 1.5.1.0". Do you think it's enough secure? Better Offuscator?

Now i've added the code by jaclaz:

@ECHO OFF

SETLOCAL

IF /I "%1"=="welcome" GOTO :%1

Echo Sorry!

GOTO :EOF

:welcome

echo welcome

But if an expert user will decrypt my batch, this method will be vain.

0

Share this post


Link to post
Share on other sites

This seem to me "good enough":

http://www.f2ko.de/programs.php?lang=en&pid=b2e

But we also have an IDE for batch files :w00t::

http://sourceforge.net/projects/batchcompiler/

And also a new thingy , Visualbatch :ph34r: :

http://visualbatch.sourceforge.net/

The good ol' way:

http://www.ericphelps.com/batch/samples/obfuscating.txt

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Guys, i've decided to use for now this converter: http://www.f2ko.de/programs.php?lang=en&pid=b2e

It's free. Now i've an issue. Compiling my batch with this code:

@ECHO OFF

SETLOCAL

IF /I "%1"=="welcome" GOTO :%1

Echo Sorry!

GOTO :EOF

:welcome

echo welcome

the exe launched with welcome option goes directly to the end of the script. With the original batch instead it's all fine.

0

Share this post


Link to post
Share on other sites

Not an answer to your last question but, if you use a batch file like this:

@ECHO OFF
ECHO=_%~1|FINDSTR/X "_-? _/?">NUL 2>&1||GOTO Sorry
REM Your scripting starts below here
ECHO=Welcome!
PAUSE
REM Your scripting ends above here
GOTO :EOF
:Sorry
ECHO= Sorry!
ECHO=
ECHO=Press any key to Exit.
PAUSE>NUL

Only users entering a parameter of /? or -? will run the script. The idea behind this is that they should be the most obvious switches to run by someone 'switched on' an unknowing user will always get the Sorry message.

0

Share this post


Link to post
Share on other sites

Hi Yzöwl, i've mixed it with one of your batch.... so this is the final result:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

COLOR F0

ECHO=_%~1|FINDSTR/X "_-123456 _/123456">NUL 2>&1||GOTO Error

FOR /R %%A IN (Windows*-KB*.EXE) DO (

ECHO= Installation of %%~nA...

>NUL PING -n 4 127.0.0.1

"%%A" /quiet /norestart)

ECHO=

ECHO= == Press any key to restart. ==

>NUL PAUSE

SHUTDOWN.EXE /r /t 0

GOTO :EOF

:Error

ECHO= Error.

ECHO=

ECHO= Press any key to exit...

PAUSE>NUL

EXIT

I've for you two questions:

1) Is this batch correct for you??

2) I compile it with this utility: http://www.f2ko.de/programs.php?lang=en&pid=b2e

Once that i launch the obtained EXE with the correct option: "file.exe /?" the batch goes directly to this string: "ECHO= == Press any key to restart. ==", jumping the FOR /R loop command.

Any idea? :yes:

Edited by Caml Light
0

Share this post


Link to post
Share on other sites

A couple of things to mention:

  1. You don't need to enable delayed expansion.
  2. If for some reason the file is run in the wrong location and there are no hotfixes found, your script would still restart the system

As far as your problem goes, I'd suggest that your 'compiler' may not be designed to pass parameters provided to it through to the script.

0

Share this post


Link to post
Share on other sites

ok, i've solved the problem cutting down from the posted code every "%~dp0" string. Now with "FOR /R %%A" it seems to work. Please Yzöwl, i've copied your batch from an another topic, and you had enabled delayed expansion there. So, cleaning all the code as you know to do... how do you could to rewrite the code i've posted?

Thanks for your patience.

Edited by Caml Light
0

Share this post


Link to post
Share on other sites
@ECHO OFF
ECHO=_%~1|FINDSTR/X "_-123456 _/123456">NUL 2>&1||GOTO Error
SETLOCAL ENABLEEXTENSIONS
SET "_="
PUSHD %~dp0
FOR /R %%A IN (Windows*-KB*.EXE) DO (
SET _=T
ECHO= Installazione di %%~nA in corso...
>NUL PING -n 4 127.0.0.1
"%%A" /quiet /norestart)
IF NOT DEFINED _ GOTO Error
ECHO=
ECHO= == Press any key to restart. ==
>NUL PAUSE
SHUTDOWN.EXE /r /t 0
GOTO :EOF
:Error
ECHO= Error.
ECHO=
ECHO= Press any key to exit...
>NUL PAUSE

0

Share this post


Link to post
Share on other sites

ok, i try it! Anyway this is the original batch you wrote:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

FOR /R "%~dp0" %%A IN (*-KB*.MSU) DO (

CALL :SUB %%~nA

ECHO= Installing KB!KB_NUM!

>NUL TIMEOUT /t 3

WUSA "%%A" /quiet /norestart)

ECHO= == Press any key to restart ==

>NUL PAUSE

SHUTDOWN.EXE /r /t 0

GOTO :EOF

:SUB

SET "KB_NUM=%*"

FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"

0

Share this post


Link to post
Share on other sites

OK Yzöwl, newly thank you for your help. The new batch works fine, but it doesn't work when i compile the batch. The problem is %~dp0 yet. Now, i don't know how solve it... is it enough to delete this string PUSHD %~dp0 ??

0

Share this post


Link to post
Share on other sites
it doesn't work when i compile the batch. The problem is %~dp0 yet. Now, i don't know how solve it... is it enough to delete this string PUSHD %~dp0 ??

I have no idea how the 'compiler' runs your batch file. (I cannot guarantee that it runs the script from its own location). Looking at the screenshot of your chosen 'compiler' it does appear that there is a temporary location in use, so you would need to either hard code the location of the parent of your directory structure or create a unique file there and let the batch search for its location first. (You could then PUSHD to that location instead of %~dp0).

0

Share this post


Link to post
Share on other sites

thank you guys :yes:

Yzöwl, is it wrong if for now i delete the PUSHD command? Without it the installation seems to work, but i don't know if i'm doing the right thing or if the batch can give problems.

Then i'd take advantage of your experience... if i'd add others FOR /R commands to install others updates, can a batch retrieve the number of installation like Windows Update? Ex: Update 1 of 5... and so on.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.