Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

CMD: OPTION to jump

- - - - -

  • Please log in to reply
32 replies to this topic

#1
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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!!


How to remove advertisement from MSFN

#2
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • OS:Windows 7 x64
  • Country: Country Flag
goto %1

:sorry
Echo Sorry!
Goto :end

:welcome
echo welcome
Goto :end

:end


just use the label name for the switch

#3
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
GREAT! Thank you very much! :thumbup

#4
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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, 30 August 2011 - 11:20 PM.


#5
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,812 posts
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.

#6
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
..and what do you suggest me to protect better my cmd script? Thanks in advance!

#7
Kelsenellenelvian

Kelsenellenelvian

    WPI Guru

  • Developer
  • 8,731 posts
  • OS:Windows 7 x64
  • Country: Country Flag
Make it into a autoit file and compile it with password...

#8
jaclaz

jaclaz

    The Finder

  • Developer
  • 13,999 posts
  • OS:none specified
  • Country: Country Flag

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, 31 August 2011 - 04:21 AM.


#9
Kelsenellenelvian

Kelsenellenelvian

    WPI Guru

  • Developer
  • 8,731 posts
  • OS:Windows 7 x64
  • Country: Country Flag
•h1_1_@m_@_|33t_p@§§vv0rd

•ÿ00_vv0n*t_cr@ç#-m3

OMG LOLZ

#10
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,812 posts
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, 31 August 2011 - 06:44 AM.


#11
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,672 posts
  • OS:Server 2012
  • Country: Country Flag

Donator

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.
MSFN RULES | GimageX HTA for PE 3.x | lol probloms
msfn2_zpsc37c7153.jpg

#12
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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.

#13
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
I've find Crypto Obfuscator, but is it only for .NET??

#14
Kelsenellenelvian

Kelsenellenelvian

    WPI Guru

  • Developer
  • 8,731 posts
  • OS:Windows 7 x64
  • Country: Country Flag
yes it looks like it

I like the looks of this:

http://www.bdargo.com/

Edited by Kelsenellenelvian, 31 August 2011 - 09:53 AM.


#15
jaclaz

jaclaz

    The Finder

  • Developer
  • 13,999 posts
  • OS:none specified
  • Country: Country Flag
This seem to me "good enough":
http://www.f2ko.de/p...lang=en&pid=b2e

But we also have an IDE for batch files :w00t::
http://sourceforge.n.../batchcompiler/

And also a new thingy , Visualbatch :ph34r: :
http://visualbatch.sourceforge.net/

The good ol' way:
http://www.ericphelp...obfuscating.txt

jaclaz

Edited by jaclaz, 31 August 2011 - 10:22 AM.


#16
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
Guys, i've decided to use for now this converter: http://www.f2ko.de/p...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.

#17
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,527 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#18
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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/p...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, 31 August 2011 - 04:26 PM.


#19
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,527 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

A couple of things to mention:
  • You don't need to enable delayed expansion.
  • 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.

#20
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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, 31 August 2011 - 04:23 PM.


#21
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,527 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

@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


#22
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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"

#23
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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 ??

#24
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,527 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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).

#25
Caml Light

Caml Light

    Junior

  • Member
  • Pip
  • 85 posts
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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN