Windows 10 Automatic Updates Enable/Disable script

Discussion in 'Windows 10' started by murphy78, Jul 18, 2015.

  1. Puremin0rez

    Puremin0rez MDL Senior Member

    Nov 24, 2010
    267
    161
    10
    Is running this still required even if I chose "notify before downloading and installing" via group policy editor?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    I don't remember. Check your updates page. It should mention automatic updates if it still needs to be set.
     
  3. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #103 s1ave77, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    FYI @ murph:

    Found that using

    Code:
    if %errorlevel% neq 0
    can lead to unpredicted behaviour due to the freestanding '0'. So i prefer

    Code:
    if not "%errorlevel%"=="0"
    One could check if thats the issue here, since the check looks valid to me :g:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    #104 murphy78, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    The problem I believe is in the way reg query detects a key that isn't present and piping the output to find.
    I could do 2x reg query but skip the 2nd if the first errors out, but there might be a better way and I don't want to half-a** it.

    Edit: actually something like this might work:
    Code:
    reg query HKLM\Blahblahblah 2>NUL|find /i "hurray">nul 2>NUL
    You see how it pipes the error channel to nul before the find pipe?
     
  5. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #105 s1ave77, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    Code:
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate" >NUL
    if not "%errorlevel%"=="0" GOTO :NOTPRESENT
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. carstenohne

    carstenohne MDL Novice

    May 22, 2010
    7
    0
    0
    Wait a bit, I have no 5 post count :( then I can send you a PM. :clap:
     
  7. qwerty12

    qwerty12 MDL Novice

    Aug 31, 2010
    49
    68
    0
    #107 qwerty12, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    Just adding the right pair of brackets around your original command seems OK to me:

    Code:
    (reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate"|find /i "0x1")>NUL 2>NUL
    
    Doesn't emit any output whatsoever, doesn't break the pipe to find, and 1 gets stored in %ERRORLEVEL% when the key doesn't exist (in which case it's fair enough to assume automatic updates are enabled) or when it's set to 0.
     
  8. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    #108 murphy78, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Good call, querty12 I totally forgot about parenthesis.
     
  9. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #109 s1ave77, Jul 27, 2015
    Last edited by a moderator: Apr 20, 2017
    Code:
    @echo off
    title Disable/Enable Windows 10 Automatic Updates
    color 1f
    :Begin UAC check and Auto-Elevate Permissions
    :-------------------------------------
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
    echo:
    echo   Requesting Administrative Privileges...
    echo   Press YES in UAC Prompt to Continue
    echo:
        goto UACPrompt
    ) else ( goto gotAdmin )
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
        "%temp%\getadmin.vbs"
        exit /B
    :gotAdmin
        if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
        pushd "%CD%"
        CD /D "%~dp0"
    :--------------------------------------
    ::===============================================================================================================
    :Check Windows Version
    wmic os get version | find /i "10.">nul 2>nul
    if not "%errorlevel%"=="0" GOTO :Not10
    ::===============================================================================================================
    :Check the key:
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate" >NUL
    if not "%errorlevel%"=="0" (
        call :HEADER "Reg Key not present.", "Would you like to set now? (Y/N)"
        CHOICE /C YN /N /M "YOUR CHOICE ?:"
        if %errorlevel%==2 goto:EXIT
        call :KEYOFF 1, "dis"
        pause
        goto:EXIT
    )
    ::===============================================================================================================
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate"|find /i "0x1" >NUL
    if "%errorlevel%"=="0" (
        call :HEADER "Automatic Updates are currently enabled.", "Would you like to disable them? (Y/N)"
        CHOICE /C YN /N /M "YOUR CHOICE ?:"
        if %errorlevel%==2 goto:EXIT
        call :KEYOFF 1, "dis"
        pause
        goto:EXIT
    )
    if not "%errorlevel%"=="0" (
        call :HEADER "Automatic Updates are currently disabled.", "Would you like to enable them? (Y/N)"
        CHOICE /C YN /N /M "YOUR CHOICE ?:"
        if %errorlevel%==2 goto:EXIT
        call :KEYOFF 2, "en"
        pause
        goto:EXIT
    )
    ::===============================================================================================================
    :KEYOFF
    echo Attempting to shut down the Windows Update service if it's running
    net stop wuauserv>NUL 2>NUL
    echo.
    Echo Changing Registry key
    REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate" /D %~1 /T REG_DWORD /F>NUL 2>NUL
    if not "%errorlevel%"=="0" goto:ERROR
    Echo.
    Echo Automatic Updates have been %~abled
    Echo.
    goto:eof
    ::===============================================================================================================
    :HEADER
    echo ============================================================
    echo %~1
    echo %~2
    echo ============================================================
    echo.
    goto:eof
    ::===============================================================================================================
    :QUIT
    echo ============================================================
    echo Press any key to exit...
    echo ============================================================
    pause>NUL
    exit
    ::===============================================================================================================
    :ERROR
    echo ============================================================
    echo The script ran into an unexpected error setting reg key.
    echo Press any key to exit...
    echo ============================================================
    pause>NUL
    exit
    ::===============================================================================================================
    :Not10
    echo ============================================================
    echo This script is only designed for Windows 10...
    echo Press any key to exit...
    echo ============================================================
    pause>NUL
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    Love your edit s1ave77. I already uploaded a v3 to the servers and updated OP, tho :(
    Perhaps we can use it on a settings script in the future or something? There's a lot of little registry tweaks that are popular like telemetry, defender updates, defender disable, perhaps store auto-update settings...

    I gotta run soon to pick up my daughter, but perhaps another time?
     
  11. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Didn't battle with parsing the Tweaks Thread Mess so far :hmm:. Would like to have all needed tweaks at one place, since i will include in JATD also.

    Wouldn't be that hard to create a manual standalone version likewise thou :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    Hard part of a lot of those tweaks is that I have no idea what they do or what they're for so I usually can only judge by the reg key name.
     
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Is my next project to check the useful tweaks :rolleyes:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. TeamOS

    TeamOS MDL Guru

    May 27, 2013
    3,036
    1,739
    120
    that works better using sysprep but works also online ...they just may ask press couple times (R):D:D
     
  16. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    For that reason i initially implemented it. I also use it to check WU without the need to use crappy UI.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. carstenohne

    carstenohne MDL Novice

    May 22, 2010
    7
    0
    0
    Now it works perfectly.:bounce4:

    Many Thanks
     
  18. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    @ murph

    Btw, once one begins to understand how to use call command to hand-over values, one can spare tons of redundant code (JATD lost 3000 lines in last refresh) :good3:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. bmurphr1

    bmurphr1 MDL Junior Member

    Aug 19, 2009
    59
    44
    0
    My main issue about forced updates is that it asks me when I want to reboot my computer, and it doesn't give me an option to permanently postpone the reboot. Obviously I will eventually have to reboot my computer, but I host a variety of server-type applications and such and I VERY rarely actually reboot my computer. When I upgrade to Windows 10 it's going to by default force me to reboot every time there's a new windows update that upgrades certain system files. Just by paying attention to the non-build update hotfixes that WU has installed, it's forced me to reboot my computer on average twice a week. Forcing me to reboot my computer every 2-3 days is unacceptable to me and it seems like the only surefire way of preventing this from happening is using murphy78's script to stop the wuaserv service temporarily until I can manually check for updates, install them all, and then reboot.