.net 4.5.2 install script

Discussion in 'Scripting' started by cocachris89, Apr 23, 2015.

  1. cocachris89

    cocachris89 MDL Senior Member

    Mar 1, 2013
    492
    147
    10
    #1 cocachris89, Apr 23, 2015
    Last edited by a moderator: Apr 20, 2017
    Hey everyone,

    I'm trying to make a batch script to uninstall 3 specific updates (from either x86 or x64 versions of Windows) from an online windows OS, install .net 4.5.2 and then reboot the PC.

    So far I have this:

    Code:
    @echo off
    set ARCH=%PROCESSOR_ARCHITECTURE%
    
    echo Now fixing .net Framework 4.5.2
    
    if %ARCH%==x86 (
    echo Removing Packages...
    start /wait /b dism /Online /Remove-Package /PackageName:Package_for_KB3008627~31bf3856ad364e35~x86~~6.1.1.0 /PackageName:Package_for_KB3000988~31bf3856ad364e35~x86~~6.1.1.1 /PackageName:Package_for_KB2918614~31bf3856ad364e35~x86~~6.1.1.4 /norestart
    echo Installing .net Framework 4.5.2
    start /wait NDP452-KB2901907-x86-x64-AllOS-ENU.exe /passive
    echo Rebooting...
    start /wait shutdown /r /t 00
    ) 
    
    if %ARCH%==amd64 (
    echo Removing Packages...
    start /wait /b dism /Online /Remove-Package /PackageName:Package_for_KB3008627~31bf3856ad364e35~amd64~~6.1.1.0 /PackageName:Package_for_KB3000988~31bf3856ad364e35~amd64~~6.1.1.1 /PackageName:Package_for_KB2918614~31bf3856ad364e35~amd64~~6.1.1.4 /norestart
    echo Installing .net Framework 4.5.2
    start /wait NDP452-KB2901907-x86-x64-AllOS-ENU.exe /passive /promtrestart
    echo Rebooting...
    start /wait shutdown /r /t 00
    )
    
    The problem I'm facing is that all three tasks start at once, not going in order, and waiting until each one is finished. It's also not echoing the right text after each task is finished.

    Its been a long day for me and I'm probably having a brainfart o_O
     
  2. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,475
    627
    60
    #2 Flipp3r, Apr 23, 2015
    Last edited by a moderator: Apr 20, 2017
    Here's what I have (from Audit mode so I'm already Admin):
    Code:
    @echo off
    TITLE --- Dot Net 4.5.2 Installation ---
    
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    
    echo Installing Dot Net 4.5.2 ...
    Start /wait %PTH%DotNet\NDP452-KB2901907-x86-x64-AllOS-ENU /passive /norestart
    
    goto %PROCESSOR_ARCHITECTURE%
    
    :AMD64
    FOR /R "%PTH%DotNet\Updates\" %%A IN (NDP45*x64*.exe) DO (
            CALL :SUB %%~nA        
        ECHO= Installing KB!KB_NUM!        
        "%%A" /passive /norestart)
    GOTO Done
    
    :x86
    FOR /R "%PTH%DotNet\Updates\" %%A IN (NDP45*x86*.exe) DO (
            CALL :SUB %%~nA        
        ECHO= Installing KB!KB_NUM!        
        "%%A" /passive /norestart)
    GOTO Done
    
    
    :SUB
    SET "KB_NUM=%*"
    FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"
    goto:EOF
    
    
    :Done
    shutdown -r -f -t 0
    
    Folder Structure:
    Code:
    InstallDotNet.cmd
    DotNet\NDP452-KB2901907-x86-x64-AllOS-ENU.exe
    DotNet\Updates\NDP45-KB2972107-x64.exe
    DotNet\Updates\NDP45-KB2972107-x86.exe
    DotNet\Updates\NDP45-KB2972216-x64.exe
    DotNet\Updates\NDP45-KB2972216-x86.exe
    DotNet\Updates\NDP45-KB2978128-x64.exe
    DotNet\Updates\NDP45-KB2978128-x86.exe
    DotNet\Updates\NDP45-KB2979578-v2-x64.exe
    DotNet\Updates\NDP45-KB2979578-v2-x86.exe
    DotNet\Updates\NDP45-KB3037581-x64.exe
    DotNet\Updates\NDP45-KB3037581-x86.exe
     
  3. cocachris89

    cocachris89 MDL Senior Member

    Mar 1, 2013
    492
    147
    10
    #3 cocachris89, Apr 24, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok, I found the problem.

    Code:
    start /wait /b
    This command doesn't work correctly. The /wait argument is ignored.

    Code:
    start /b /wait
    This command DOES work :D.