You can learn a little bit of batch scripting from this batch: ex: You can use the cmd command: "openfiles" to check if you are Administrator. The Command: Code: Powershell -Command "& {dir | Unblock-File}" Unblocks all the downloaded files from internet or from another computer (it prevents the warning thus the script won't pause) If you check the script you will learn how to make the script count files (math operations) "set /A totalexe = totalexe + 1" (To make math works on batch scripts you need enable "setlocal EnableDelayedExpansion") Take a look, you are free to use or improve the script.
Thanks for script & small tutorial... Need one help as all downloaded files are not in one folder, then what to add in script so that it search & execute files inside folders inside root folder...
It is easier to search for *.msu and move or copy all the patches to a single folder. If you intend to change the script like you told me then it will change 30% of the script. Some parts will look like this: Code: for /D %%d in (*) do ( cd %%d call :Function cd .. ) Try this code and let me know: FileName: Update-Recursive.cmd Spoiler Code: @echo off setlocal EnableDelayedExpansion cls title Windows 8.1 Offline Updater color 1F set BATDIR1=%~dp0 cd /d %BATDIR1% :Check-Admin openfiles >nul 2>&1 if %errorlevel% NEQ 0 goto :required :UnblockFiles cls echo Unblocking Files echo+ echo Executing Powershell... echo+ for /D %%d in (*) do ( cd %%d Powershell -Command "& {dir | Unblock-File}" cd .. ) title Windows 8.1 Offline Updater echo+ :Counters set /A countermsu=0 set /A counterexe=0 set /A totalmsu=0 set /A totalexe=0 for /D %%d in (*) do ( cd %%d @for %%V in (*.msu) do ( set /A totalmsu = totalmsu + 1 ) @for %%V in (*.exe) do ( set /A totalexe = totalexe + 1 ) cd .. ) :Menu cls Echo+ Echo ------------------------------------------------------------------------------- Echo Windows 8.1 Off-Line Updates Package: OEM Echo ------------------------------------------------------------------------------- Echo+ echo Hello %USERNAME%, what do you want to do? echo+ echo A) Install Critical Updates (MSU: %totalmsu%) (EXE: %totalexe%) echo B) View Installed Updates echo Q) Exit echo+ set /p userinp= ^> Select Option : set userinp=%userinp:~0,1% if /i "%userinp%"=="Q" exit if /i "%userinp%"=="A" goto :Patches_Install if /i "%userinp%"=="B" goto :Patches_List goto :Menu :Patches_List If exist patchlist.txt del patchlist.txt wmic qfe get hotfixid >patchlist.txt start patchlist.txt goto :Menu exit :Patches_Install cls Echo+ Echo ------------------------------------------------------------------------------- Echo Windows 8.1 Off-Line Updates Package: OEM Echo ------------------------------------------------------------------------------- Echo+ echo+ echo Installing OEM Patches... echo+ for /D %%d in (*) do ( cd %%d echo Folder %%d @for %%V in (*.exe) do ( set /A counterexe = counterexe + 1 echo Installing !counterexe! of %totalexe% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) @for %%V in (*.msu) do ( set /A countermsu = countermsu + 1 echo Installing !countermsu! of %totalmsu% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) cd .. echo+ ) echo+ echo *********** echo Complete! echo *********** echo+ Pause cd.. Exit :required cls color 0f echo Run the script as Administrator echo+ echo Correr el script como Administrador echo+ pause exit This code will go +1 level only: Root Folder --> SubFolder --> Files ( *.msu or *.exe )
Afaik Code: for /r "path\to\folder" %%V in (*.msu) do ( ) should recurse through all sub-directories . EDIT: can confirm it does indeed .
Just checked: where Code: for %%V in (*.msu) do ( ) checks the directory only. Code: for /r %%V in (*.msu) do ( ) recurses all sub-directories.
I must go now... (Will return on sunday) (small trip.) @s1ave77 Can you help integrating the recursive loop in the main script? It has to work fully like this: * The PowerShell File Unblock function in each folder * The *.msu and *.exe file count * The patches installation (obviously) Thanks Another thing: Code: for /r "%BATDIR1%" %%d in (.) do ( cd %%d Powershell -Command "& {dir | Unblock-File}" cd .. ) I did not try this... but this should execute the unblock files in each directory. am i correct?
Hmm, if i got the challenge correctly it only needs to add the /r switch to the original code. As the script is copied to the main upadate folder, there's no need to specify any pathes additionally: Code: :Patches_Install cls Echo+ Echo ------------------------------------------------------------------------------- Echo Windows 8.1 Off-Line Updates Package: OEM Echo ------------------------------------------------------------------------------- Echo+ echo+ echo Installing OEM Patches... echo+ @for /r %%V in (*.exe) do ( set /A counterexe = counterexe + 1 echo Installing !counterexe! of %totalexe% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) @for /r %%V in (*.msu) do ( set /A countermsu = countermsu + 1 echo Installing !countermsu! of %totalmsu% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) Should be indeed that easy. Now it recurses the update folder when installing (updates only need to be in any sub-folder beneath) ... rest of the code doesn't change. ================================ EDIT: OK, not sure whether powershell recurses ... any clue?
With following changes script is working fine. Tested for unblock & patch install.... Thank you ColdZero & s1ave77.... Code: @echo off setlocal EnableDelayedExpansioncls title Windows 8.1 Offline Updater color 1F set BATDIR1=%~dp0 cd /d %BATDIR1% :Check-Admin openfiles >nul 2>&1 if %errorlevel% NEQ 0 goto :required :UnblockFiles cls echo Unblocking Files echo+ echo Executing Powershell... echo+ Powershell -Command "& {ls -r | unblock-file}" title Windows 8 Offline Updater echo+ :Counters set /A countermsu=0 set /A counterexe=0 set /A totalmsu=0 set /A totalexe=0 @for %%V in (*.msu) do ( set /A totalmsu = totalmsu + 1 ) @for %%V in (*.exe) do ( set /A totalexe = totalexe + 1 ) :Menu cls Echo+ Echo ------------------------------------------------------------------------------- Echo Windows 8.1 Off-Line Updates Package: OEM Echo ------------------------------------------------------------------------------- Echo+ echo Hello %USERNAME%, what do you want to do? echo+ echo A) Install Critical Updates (MSU: %totalmsu%) (EXE: %totalexe%) echo B) View Installed Updates echo Q) Exit echo+ set /p userinp= ^> Select Option : set userinp=%userinp:~0,1% if /i "%userinp%"=="Q" exit if /i "%userinp%"=="A" goto :Patches_Install if /i "%userinp%"=="B" goto :Patches_List goto :Menu :Patches_List If exist patchlist.txt del patchlist.txt wmic qfe get hotfixid >patchlist.txt start patchlist.txt goto :Menu exit :Patches_Install cls Echo+ Echo ------------------------------------------------------------------------------- Echo Windows 8.1 Off-Line Updates Package: OEM Echo ------------------------------------------------------------------------------- Echo+ echo+ echo Installing OEM Patches... echo+ @for /r %%V in (*.exe) do ( set /A counterexe = counterexe + 1 echo Installing !counterexe! of %totalexe% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) @for /r %%V in (*.msu) do ( set /A countermsu = countermsu + 1 echo Installing !countermsu! of %totalmsu% echo %%V %%V /quiet /norestart If %errorlevel% NEQ 0 echo Warning: Minor error! "dont worry" echo+ ) echo+ echo *********** echo Complete! echo *********** echo+ Pause cd.. Exit :required cls color 0f echo Run the script as Administrator echo+ echo Correr el script como Administrador echo+ pause exit
All the scripts works, thanks guys! I have a minor minor problem. On file "Update 2.2 - Recursive Deep.cmd" When the script goes thru the *.msu or *.exe it echoes the "+" instead of a blank line. any ideas why the script does that? PostNote: I am borrowing a laptop.