Caml Light Posted August 31, 2011 Author Share Posted August 31, 2011 Guys, i've decided to use for now this converter: http://www.f2ko.de/programs.php?lang=en&pid=b2eIt's free. Now i've an issue. Compiling my batch with this code:@ECHO OFFSETLOCALIF /I "%1"=="welcome" GOTO :%1Echo Sorry!GOTO :EOF:welcomeecho welcomethe 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 More sharing options...
Yzöwl Posted August 31, 2011 Share Posted August 31, 2011 Not an answer to your last question but, if you use a batch file like this:@ECHO OFFECHO=_%~1|FINDSTR/X "_-? _/?">NUL 2>&1||GOTO SorryREM Your scripting starts below hereECHO=Welcome!PAUSEREM Your scripting ends above hereGOTO :EOF:SorryECHO= Sorry!ECHO=ECHO=Press any key to Exit.PAUSE>NULOnly 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 More sharing options...
Caml Light Posted August 31, 2011 Author Share Posted August 31, 2011 (edited) Hi Yzöwl, i've mixed it with one of your batch.... so this is the final result:@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONCOLOR F0ECHO=_%~1|FINDSTR/X "_-123456 _/123456">NUL 2>&1||GOTO ErrorFOR /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 PAUSESHUTDOWN.EXE /r /t 0GOTO :EOF:ErrorECHO= Error.ECHO=ECHO= Press any key to exit...PAUSE>NULEXITI'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=b2eOnce 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? Edited August 31, 2011 by Caml Light Link to comment Share on other sites More sharing options...
Yzöwl Posted August 31, 2011 Share Posted August 31, 2011 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 systemAs 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 More sharing options...
Caml Light Posted August 31, 2011 Author Share Posted August 31, 2011 (edited) 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 August 31, 2011 by Caml Light Link to comment Share on other sites More sharing options...
Yzöwl Posted August 31, 2011 Share Posted August 31, 2011 @ECHO OFFECHO=_%~1|FINDSTR/X "_-123456 _/123456">NUL 2>&1||GOTO ErrorSETLOCAL ENABLEEXTENSIONSSET "_="PUSHD %~dp0FOR /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 ErrorECHO=ECHO= == Press any key to restart. ==>NUL PAUSESHUTDOWN.EXE /r /t 0GOTO :EOF:ErrorECHO= Error.ECHO=ECHO= Press any key to exit...>NUL PAUSE Link to comment Share on other sites More sharing options...
Caml Light Posted August 31, 2011 Author Share Posted August 31, 2011 ok, i try it! Anyway this is the original batch you wrote:@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONFOR /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 PAUSESHUTDOWN.EXE /r /t 0GOTO :EOF:SUBSET "KB_NUM=%*"FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B" Link to comment Share on other sites More sharing options...
Caml Light Posted August 31, 2011 Author Share Posted August 31, 2011 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 More sharing options...
Yzöwl Posted September 1, 2011 Share Posted September 1, 2011 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 More sharing options...
Caml Light Posted September 1, 2011 Author Share Posted September 1, 2011 thank you guys 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 More sharing options...
Yzöwl Posted September 1, 2011 Share Posted September 1, 2011 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 More sharing options...
Caml Light Posted September 6, 2011 Author Share Posted September 6, 2011 Hi Yzöwl! 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 OFFECHO=_%~1|FINDSTR/X "_-123456 _/123456">NUL 2>&1||GOTO ErrorSETLOCAL ENABLEEXTENSIONSSET "_="PUSHD %~dp0FOR /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 ErrorECHO=ECHO= == Press any key to restart. ==>NUL PAUSESHUTDOWN.EXE /r /t 0GOTO :EOF:ErrorECHO= Error.ECHO=ECHO= Press any key to exit...>NUL PAUSE Link to comment Share on other sites More sharing options...
allen2 Posted September 6, 2011 Share Posted September 6, 2011 You just need to add a ">c:\path_you_want\logfile.log" at the end of each echo command. Link to comment Share on other sites More sharing options...
Caml Light Posted September 6, 2011 Author Share Posted September 6, 2011 thanks!! Anyway, i've tried with a only ">" and the log register only this: "ECHO= == Press any key to restart. =="While with two ">>" the log register all installations. Do you know why? Link to comment Share on other sites More sharing options...
bphlpt Posted September 6, 2011 Share Posted September 6, 2011 (edited) 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 September 6, 2011 by bphlpt Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now