Jump to content

CMD: OPTION to jump


Recommended Posts

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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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

Link to comment
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"

Link to comment
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 ??

Link to comment
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).

Link to comment
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.

Link to comment
Share on other sites

For /R without a path should walk the tree rooted from the current directory. If the file is run from within that directory you will be fine, if you run it from elsewhere or the 'compiler' runs it from a temporary directory, it will walk the wrong path structure.

What I would suggest is that if your 'compiler' is unable to handle something as simple as %0 derivatives , then it really doesn't serve much purpose unless you always have control over the environment within which it will be run.

The script could be edited/modified to run each update echoing a count to the screen.

Link to comment
Share on other sites

Hi Yzöwl! :hello:

Is it possible to add the log support to your code below? I try to explain me better... During every installation, in this case of Windows hotfixes, is it possible to save to a file (.log or .txt) what is happening?

For example, the log file shoud be:

Installation of KB123456....

Installation of KB234567....

Installation of KB345678....

and so on...

(Congratulations for your batch, you helped me very much!!)

@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

Link to comment
Share on other sites

One ">" means, roughly, "redirect output and write to here", ie open the file, write the info (replacing whatever was there), and close the file.

Two ">>" means, roughly, "redirect output and append to here", ie open the file, write the info (adding to the end of whatever was there), and close the file.

Cheers and Regards

Edited by bphlpt
Link to comment
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.
×
×
  • Create New...