daily pastebin goal
33%
SHARE
TWEET

Win7-8-8.1 Remove Telemetry

a guest Nov 9th, 2017 237 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. title "Remove Microsoft® Telemetry and Annoyances"
  3. endlocal & setlocal EnableDelayedExpansion
  4.  
  5. rem Script Updated by <bar on 11/11/2017>
  6. rem Script Updated by <https://github.com/simdol>
  7. rem Script Originally Created by <github.com/tarampampam> #2015
  8. rem Script Version: 0.3.4 <11/26/2016>
  9. rem Supports: Microsoft Windows 7/8/8.1
  10.  
  11. echo.
  12. echo   ***************************************************************************
  13. echo   *                                                                         *
  14. echo   *                   Remove MS Telemetry and Annoyances                    *
  15. echo   *                                                                         *
  16. echo   ***************************************************************************
  17. echo   *                                                                         *
  18. echo   * You can use these arguments:                                            *
  19. echo   *                                                                         *
  20. echo   *   -kb ^| -hotfixes Do NOT uninstall updates                              *
  21. echo   *   -d  ^| -disable  Do NOT disable updates                                *
  22. echo   *   -t  ^| -tasks    Do NOT disable tasks                                  *
  23. echo   *   -s  ^| -services Do NOT disable services                               *
  24. echo   *   -i  ^| -ip       Do NOT block IP addresses using route                 *
  25. echo   *   -f  ^| -firewall Do NOT block IP addresses using firewall              *
  26. echo   *   -h  ^| -hosts    Do NOT add domains to the hosts file                  *
  27. echo   *   -u  ^| -updates  Do NOT change Windows Update settings                 *
  28. echo   *   -l  ^| -log      Do NOT write any messages to .log file                *
  29. echo   *   -e  ^| -exit     Exit when done                                        *
  30. echo   *                                                                         *
  31. echo   * You can find the latest version here:                                   *
  32. echo   *   ^<^http://preview.tinyurl.com/j9pvtw2^>                                  *
  33. echo   *                                                                         *
  34. echo   ***************************************************************************
  35. echo   *                                                                         *
  36. echo   *                          WARNING WARNING WARNING                        *
  37. echo   *            BEFORE PROCEEDING, PLEASE READ THE DOCUMENTATION             *
  38. echo   *                                                                         *
  39. echo   ***************************************************************************
  40. echo.
  41.  
  42. rem Set up default script values and declare variables
  43. set ExitOnComplete=0
  44. set WriteLogFile=1
  45. set UninstallUpdates=1
  46. set DisableUpdates=1
  47. set DisableTasks=1
  48. set DisableServices=1
  49. set BlockIPaddresses=1
  50. set BlockIPaddressesWithFirewall=1
  51. set AddDomainsToHosts=1
  52. set DisableAutomaticUpdates=1
  53.  
  54. set FirewallIPlist=
  55. set UpdatesList=
  56. set result=
  57. set LogFilePath="%~f0.log"
  58.  
  59. rem Parse passed arguments to script
  60. :parse_passed_params
  61.   if "%~1"=="" goto end_parse_passed_params
  62.   if "%~1"=="-e"        set ExitOnComplete=1
  63.   if "%~1"=="-exit"     set ExitOnComplete=1
  64.   if "%~1"=="-kb"       set UninstallUpdates=0
  65.   if "%~1"=="-hotfixes" set UninstallUpdates=0
  66.   if "%~1"=="-d"        set DisableUpdates=0
  67.   if "%~1"=="-disable"  set DisableUpdates=0
  68.   if "%~1"=="-t"        set DisableTasks=0
  69.   if "%~1"=="-tasks"    set DisableTasks=0
  70.   if "%~1"=="-s"        set DisableServices=0
  71.   if "%~1"=="-services" set DisableServices=0
  72.   if "%~1"=="-i"        set BlockIPaddresses=0
  73.   if "%~1"=="-ip"       set BlockIPaddresses=0
  74.   if "%~1"=="-f"        set BlockIPaddressesWithFirewall=0
  75.   if "%~1"=="-firewall" set BlockIPaddressesWithFirewall=0
  76.   if "%~1"=="-h"        set AddDomainsToHosts=0
  77.   if "%~1"=="-hosts"    set AddDomainsToHosts=0
  78.   if "%~1"=="-u"        set DisableAutomaticUpdates=0
  79.   if "%~1"=="-updates"  set DisableAutomaticUpdates=0
  80.   if "%~1"=="-l"        set WriteLogFile=0
  81.   if "%~1"=="-log"      set WriteLogFile=0
  82.   shift & goto parse_passed_params
  83. :end_parse_passed_params
  84.  
  85. goto:checkPermissions
  86. :begin
  87.  
  88. if %UninstallUpdates%==1 (
  89.   call:title "1/8 - Uninstalling evil updates.."
  90.   rem You can find KB descriptions here: https://support.microsoft.com/en-us/kb/%KB_NUMBER%
  91.  
  92.   for %%? in (
  93.     "2505438"
  94.     "2670838"
  95.     "2882822"
  96.     "2902907"
  97.     "2952664"
  98.     "2976978"
  99.     "2976987"
  100.     "2977759"
  101.     "2990214"
  102.     "2999226"
  103.     "3012973"
  104.     "3013791"
  105.     "3015249"
  106.     "3018467"
  107.     "3126030"
  108.     "3021917"
  109.     "3022345"
  110.     "3029432"
  111.     "3029603"
  112.     "3029606"
  113.     "3035583"
  114.     "3041857"
  115.     "3042058"
  116.     "3044374"
  117.     "3044374"
  118.     "3045634"
  119.     "3045746"
  120.     "3046480"
  121.     "3050265"
  122.     "3050267"
  123.     "3053863"
  124.     "3054256"
  125.     "3054464"
  126.     "3055323"
  127.     "3055343"
  128.     "3056347"
  129.     "3058168"
  130.     "3059316"
  131.     "3060383"
  132.     "3060746"
  133.     "3060793"
  134.     "3061493"
  135.     "3063843"
  136.     "3064059"
  137.     "3064683"
  138.     "3065013"
  139.     "3065987"
  140.     "3065988"
  141.     "3068707"
  142.     "3068708"
  143.     "3071663"
  144.     "3072019"
  145.     "3072318"
  146.     "3074677"
  147.     "3075249"
  148.     "3075851"
  149.     "3075853"
  150.     "3078405"
  151.     "3078676"
  152.     "3079318"
  153.     "3080042"
  154.     "3080149"
  155.     "3080800"
  156.     "3081437"
  157.     "3081454"
  158.     "3081954"
  159.     "3083324"
  160.     "3083325"
  161.     "3083710"
  162.     "3083711"
  163.     "3084905"
  164.     "3086255"
  165.     "3087041"
  166.     "3087137"
  167.     "3088195"
  168.     "3090045"
  169.     "3091297"
  170.     "3092627"
  171.     "3093983"
  172.     "3095701"
  173.     "3096433"
  174.     "3099834"
  175.     "3100919"
  176.     "3100956"
  177.     "3102429"
  178.     "3102810"
  179.     "3102812"
  180.     "3103696"
  181.     "3103699"
  182.     "3107998"
  183.     "3112148"
  184.     "3112336"
  185.     "3112343"
  186.     "3118401"
  187.     "3121255"
  188.     "3121260"
  189.     "3121261"
  190.     "3123242"
  191.     "3123862"
  192.     "3124280"
  193.     "3125210"
  194.     "3126033"
  195.     "3128650"
  196.     "3130896"
  197.     "3132080"
  198.     "3133924"
  199.     "3133977"
  200.     "3134815"
  201.     "3135445"
  202.     "3135449"
  203.     "3138612"
  204.     "3138615"
  205.     "3139921"
  206.     "3139923"
  207.     "3139929"
  208.     "3146449"
  209.     "3148198"
  210.     "3150513"
  211.     "3161102"
  212.     "3170735"
  213.     "3173040"
  214.     "3184143"
  215.     "971033"
  216.   ) do call:uninstall_update %%?
  217. )
  218.  
  219. if %DisableUpdates%==1 (
  220.   call:title "2/8 - Disabling ^(hiding^) uninstalled updates.."
  221.   call:log "It can take a lot of time, please wait or use -d flag to disable this feature.." "NOTE"
  222.   rem To do this, you must init updates list by calling 'call:uninstall_update "123123"' first!
  223.   call:disable_updates
  224. )
  225.  
  226. if %DisableTasks%==1 (
  227.   call:title "3/8 - Disabling unneeded scheduled tasks.."
  228.   for %%? in (
  229.     "\Microsoft\Windows\Application Experience\AitAgent"
  230.     "\Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser"
  231.     "\Microsoft\Windows\Application Experience\ProgramDataUpdater"
  232.     "\Microsoft\Windows\Autochk\Proxy"
  233.     "\Microsoft\Windows\Customer Experience Improvement Program\Consolidator"
  234.     "\Microsoft\Windows\Customer Experience Improvement Program\KernelCeipTask"
  235.     "\Microsoft\Windows\Customer Experience Improvement Program\UsbCeip"
  236.     "\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector"
  237.     "\Microsoft\Windows\PI\Sqm-Tasks"
  238.     "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem"
  239.     "\Microsoft\Windows\Windows Error Reporting\QueueReporting"
  240.     "\Microsoft\Windows\Maintenance\WinSAT"
  241.     "\Microsoft\Windows\Media Center\ActivateWindowsSearch"
  242.     "\Microsoft\Windows\Media Center\ConfigureInternetTimeService"
  243.     "\Microsoft\Windows\Media Center\DispatchRecoveryTasks"
  244.     "\Microsoft\Windows\Media Center\ehDRMInit"
  245.     "\Microsoft\Windows\Media Center\InstallPlayReady"
  246.     "\Microsoft\Windows\Media Center\mcupdate"
  247.     "\Microsoft\Windows\Media Center\MediaCenterRecoveryTask"
  248.     "\Microsoft\Windows\Media Center\ObjectStoreRecoveryTask"
  249.     "\Microsoft\Windows\Media Center\OCURActivate"
  250.     "\Microsoft\Windows\Media Center\OCURDiscovery"
  251.     "\Microsoft\Windows\Media Center\PBDADiscovery"
  252.     "\Microsoft\Windows\Media Center\PBDADiscoveryW1"
  253.     "\Microsoft\Windows\Media Center\PBDADiscoveryW2"
  254.     "\Microsoft\Windows\Media Center\PvrRecoveryTask"
  255.     "\Microsoft\Windows\Media Center\PvrScheduleTask"
  256.     "\Microsoft\Windows\Media Center\RegisterSearch"
  257.     "\Microsoft\Windows\Media Center\ReindexSearchRoot"
  258.     "\Microsoft\Windows\Media Center\SqlLiteRecoveryTask"
  259.     "\Microsoft\Windows\Media Center\UpdateRecordPath"
  260.   ) do call:disable_task %%?
  261. )
  262.  
  263. if %DisableServices%==1 (
  264.   call:title "4/8 - Disabling unneeded services.."
  265.   for %%? in (
  266.     "Diagtrack"
  267.     "dmwappushservice"
  268.     "WerSvc"
  269.   ) do call:disable_service %%?
  270.  
  271.   set RegDataCollection="HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DataCollection"
  272.   reg query !RegDataCollection!>nul 2>&1 & if %errorLevel%==0 (
  273.     reg add !RegDataCollection! /v AllowTelemetry /t REG_DWORD /d 0 /f >nul
  274.   )
  275.  
  276.   set RegWindowsReporting="HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting"
  277.   reg query !RegWindowsReporting!>nul 2>&1 & if %errorLevel%==0 (
  278.     reg add !RegWindowsReporting! /v Disabled /t REG_DWORD /d 1 /f >nul
  279.   )
  280. )
  281.  
  282. if %BlockIPaddresses%==1 (
  283.   call:title "5/8 - Blocking MS servers' IP addresses.."
  284.   for %%? in (
  285.     "111.221.29.177"
  286.     "111.221.29.253"
  287.     "131.253.40.37"
  288.     "134.170.30.202"
  289.     "134.170.115.60"
  290.     "134.170.165.248"
  291.     "134.170.165.253"
  292.     "134.170.185.70"
  293.     "137.116.81.24"
  294.     "137.117.235.16"
  295.     "157.55.129.21"
  296.     "157.55.133.204"
  297.     "157.56.121.89"
  298.     "157.56.91.77"
  299.     "168.63.108.233"
  300.     "184.86.56.12"
  301.     "185.13.160.61"
  302.     "191.232.139.254"
  303.     "191.232.80.58"
  304.     "191.232.80.62"
  305.     "191.237.208.126"
  306.     "204.79.197.200"
  307.     "207.46.101.29"
  308.     "207.46.114.58"
  309.     "207.46.223.94"
  310.     "207.68.166.254"
  311.     "212.30.134.204"
  312.     "212.30.134.205"
  313.     "23.102.21.4"
  314.     "23.99.10.11"
  315.     "23.218.212.69"
  316.     "64.4.54.22"
  317.     "64.4.54.32"
  318.     "64.4.6.100"
  319.     "65.39.117.230"
  320.     "65.52.100.11"
  321.     "65.52.100.7"
  322.     "65.52.100.9"
  323.     "65.52.100.91"
  324.     "65.52.100.92"
  325.     "65.52.100.93"
  326.     "65.52.100.94"
  327.     "65.52.108.29"
  328.     "65.55.108.23"
  329.     "65.55.138.114"
  330.     "65.55.138.126"
  331.     "65.55.138.186"
  332.     "65.55.252.63"
  333.     "65.55.252.71"
  334.     "65.55.252.92"
  335.     "65.55.252.93"
  336.     "65.55.29.238"
  337.     "65.55.39.10"
  338.   ) do call:block_route %%?
  339. )
  340.  
  341. if %BlockIPaddressesWithFirewall%==1 (
  342.   call:title "6/8 - Blocking IP addresses by firewall rules.."
  343.   rem To do this, you must init IP addresses list by calling 'call:block_route "1.1.1.1"' first!
  344.   call:block_routes_with_firewall
  345. )
  346.  
  347. if %AddDomainsToHosts%==1 (
  348.   call:title "7/8 - Finding and adding MS domains to HOSTS file ^(to block^).."
  349.   for %%? in (
  350.     "--title--"
  351.     "msedge.net"
  352.     "a-msedge.net"
  353.     "a-0001.a-msedge.net"
  354.     "a-0002.a-msedge.net"
  355.     "a-0003.a-msedge.net"
  356.     "a-0004.a-msedge.net"
  357.     "a-0005.a-msedge.net"
  358.     "a-0006.a-msedge.net"
  359.     "a-0007.a-msedge.net"
  360.     "a-0008.a-msedge.net"
  361.     "a-0009.a-msedge.net"
  362.     "a1095.g2.akamai.net"
  363.     "ad.doubleclick.net"
  364.     "adnexus.net"
  365.     "adnxs.com"
  366.     "secure.adnxs.com"
  367.     "m.adnxs.com"
  368.     "ads1.msads.net"
  369.     "ads1.msn.com"
  370.     "ads2.msn.com"
  371.     "flex.msn.com"
  372.     "g.msn.com"
  373.     "h2.msn.com"
  374.     "h1.msn.com"
  375.     "a.ads1.msn.com"
  376.     "a.ads2.msn.com"
  377.     "a.ads2.msads.net"
  378.     "live.rads.msn.com"
  379.     "ads2.msn.com.c.footprint.net"
  380.     "aka-cdn-ns.adtech.de"
  381.     "az361816.vo.msecnd.net"
  382.     "az512334.vo.msecnd.net"
  383.     "bs.serving-sys.com"
  384.     "msntest.serving-sys.com"
  385.     "telemetry.microsoft.com"
  386.     "ca.telemetry.microsoft.com"
  387.     "c.msn.com"
  388.     "aidps.atdmt.com"
  389.     "view.atdmt.com"
  390.     "ec.atdmt.com"
  391.     "c.atdmt.com"
  392.     "db3aqu.atdmt.com"
  393.     "cdn.atdmt.com"
  394.     "choice.live.com"
  395.     "choice.microsoft.com"
  396.     "choice.microsoft.com.nsatc.net"
  397.     "compatexchange.cloudapp.net"
  398.     "corpext.msitadfs.glbdns2.microsoft.com"
  399.     "corp.sts.microsoft.com"
  400.     "cs1.wpc.v0cdn.net"
  401.     "df.telemetry.microsoft.com"
  402.     "e9946.g.akamaiedge.net"
  403.     "fe2.update.microsoft.com.akadns.net"
  404.     "fe3.delivery.dsp.mp.microsoft.com.nsatc.net"
  405.     "microsoft-hohm.com"
  406.     "feedback.microsoft-hohm.com"
  407.     "feedback.search.microsoft.com"
  408.     "feedback.windows.com"
  409.     "i1.services.social.microsoft.com"
  410.     "i1.services.social.microsoft.com.nsatc.net"
  411.     "i.s1.social.ms.akadns.net"
  412.     "lb1.www.ms.akadns.net"
  413.     "legacy-redirection-neurope-prod-hp.cloudapp.net"
  414.     "oca.telemetry.microsoft.com"
  415.     "oca.telemetry.microsoft.com.nsatc.net"
  416.     "onesettings-hk2.metron.live.com.nsatc.net"
  417.     "pre.footprintpredict.com"
  418.     "preview.msn.com"
  419.     "ads.msn.com"
  420.     "rad.msn.com"
  421.     "rad.live.com"
  422.     "b.rad.msn.com"
  423.     "b.ads2.msads.net"
  424.     "b.ads1.msn.com"
  425.     "ac3.msn.com"
  426.     "a.rad.msn.com"
  427.     "cds26.ams9.msecn.net"
  428.     "secure.flashtalking.com"
  429.     "static.2mdn.net"
  430.     "s0.2mdn.net"
  431.     "redirection.prod.cms.msn.com"
  432.     "redirection.prod.cms.msn.com.akadns.net"
  433.     "redir.metaservices.microsoft.com"
  434.     "redir.metaservices.microsoft.com.akadns.net"
  435.     "redir.metaservices.microsoft.com.edgesuite.net"
  436.     "wes.df.telemetry.microsoft.com"
  437.     "reports.wes.df.telemetry.microsoft.com"
  438.     "services.wes.df.telemetry.microsoft.com"
  439.     "settings.data.glbdns2.microsoft.com"
  440.     "settings.data.microsoft.com"
  441.     "settings-sandbox.data.glbdns2.microsoft.com"
  442.     "settings-sandbox.data.microsoft.com"
  443.     "settings-win.data.microsoft.com"
  444.     "schemas.microsoft.akadns.net"
  445.     "siweb.microsoft.akadns.net"
  446.     "sls.update.microsoft.com.akadns.net"
  447.     "spynet2.microsoft.akadns.net"
  448.     "spynet2.microsoft.com"
  449.     "spynetalt.microsoft.akadns.net"
  450.     "spynetalt.microsoft.com"
  451.     "spyneteurope.microsoft.akadns.net"
  452.     "sqm.df.telemetry.microsoft.com"
  453.     "sqm.telemetry.microsoft.com"
  454.     "sqm.telemetry.microsoft.com.nsatc.net"
  455.     "ssw.live.com"
  456.     "ssw.live.com.nsatc.net"
  457.     "statsfe1.ws.microsoft.com"
  458.     "statsfe1.ws.microsoft.com.nsatc.net"
  459.     "statsfe2.update.microsoft.com.akadns.net"
  460.     "statsfe2.ws.microsoft.com"
  461.     "statsfe2.ws.microsoft.com.nsatc.net"
  462.     "support.msn.microsoft.akadns.net"
  463.     "watson.microsoft.com"
  464.     "survey.watson.microsoft.com"
  465.     "telecommand.telemetry.microsoft.com"
  466.     "telecommand.telemetry.microsoft.com.nsatc.net"
  467.     "telemetry.appex.bing.net"
  468.     "telemetry.appex.search.prod.ms.akadns.net"
  469.     "telemetry.urs.microsoft.com"
  470.     "t.urs.microsoft.com.nsatc.net"
  471.     "vortex.data.glbdns2.microsoft.com"
  472.     "vortex.data.metron.live.com.nsatc.net"
  473.     "vortex-bn2.metron.live.com.nsatc.net"
  474.     "vortex-cy2.metron.live.com.nsatc.net"
  475.     "vortex.data.microsoft.com"
  476.     "vortex-db5.metron.live.com.nsatc.net"
  477.     "vortex-sandbox.data.glbdns2.microsoft.com"
  478.     "vortex-sandbox.data.microsoft.com"
  479.     "vortex-win.data.metron.live.com.nsatc.net"
  480.     "vortex-win.data.microsoft.com"
  481.     "watson.live.com"
  482.     "watson.microsoft.com.nsatc.net"
  483.     "watson.ppe.telemetry.microsoft.com"
  484.     "watson.telemetry.microsoft.com"
  485.     "watson.telemetry.microsoft.com.nsatc.net"
  486.   ) do call:add_to_hosts %%?
  487. )
  488.  
  489. if %DisableAutomaticUpdates%==1 (
  490.   call:title "8/8 - Disabling automatic Windows update ^(search automatically, select and install manually^)"
  491.   set RegeditRoot="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
  492.   reg add !RegeditRoot! /v AUOptions /t REG_DWORD /d 2 /f>nul
  493.   reg add !RegeditRoot! /v IncludeRecommendedUpdates /t REG_DWORD /d 0 /f>nul
  494. )
  495.  
  496. goto:end
  497.  
  498. :log
  499.   set message=%~1
  500.   set type=%~2
  501.   if [!type!] EQU [] (
  502.     set type=%time%
  503.   )
  504.   echo [!type!] %message%
  505.   if %WriteLogFile%==1 ( if [%LogFilePath%] NEQ [] (
  506.     echo [!type!] %message%>>%LogFilePath% 2>&1
  507.   ))
  508.   exit /b
  509.  
  510. :title
  511.   set title=%~1
  512.   echo.
  513.   echo [i] %title%
  514.   if %WriteLogFile%==1 ( if [%LogFilePath%] NEQ [] (
  515.     echo.>>%LogFilePath% 2>&1
  516.     echo [i] %title%>>%LogFilePath% 2>&1
  517.   ))
  518.   exit /b
  519.  
  520. :checkPermissions
  521.   if exist %SystemRoot%\System32\fsutil.exe (
  522.     fsutil dirty query %systemdrive%>nul 2>&1
  523.   ) else (
  524.     net session >nul 2>&1
  525.   )
  526.   if %errorLevel%==0 (
  527.     goto:begin
  528.   ) else (
  529.     call:log "Failure: Please run this script with administrator rights"
  530.     goto:end
  531.   )
  532.   exit /b
  533.  
  534. :download_file
  535.   set url=%~1
  536.   set dest=%~2
  537.   powershell -ExecutionPolicy RemoteSigned -NoLogo -Noninteractive -Command "try { Import-Module BitsTransfer; Start-BitsTransfer -Source %url% -Destination %dest%; exit 100; } catch { exit 0; }">nul
  538.   exit /b
  539.  
  540. :install_pswu_module
  541.   set ps_modules_dir=%windir%\System32\WindowsPowerShell\v1.0\Modules
  542.   set pswu_distr_path="!ps_modules_dir!\PSWindowsUpdate"
  543.   set result=0
  544.   if exist "!pswu_distr_path!\Hide-WUUpdate.ps1" (
  545.     rem call:log "PowerShell module 'PSWindowsUpdate' found"
  546.     set result=100
  547.   ) else (
  548.     set local_unzip_tool=0
  549.     set local_pswu_module=0
  550.     call:log "0/8 - Installing PowerShell module 'PSWindowsUpdate'" "Install update"
  551.     if exist "%~dp0\unzip.exe" (
  552.       set local_unzip_tool=1
  553.       set unzip_tool="%~dp0\unzip.exe"
  554.       call:log "Local unzip tool found"
  555.     ) else (
  556.       set unzip_tool="%temp%\unzip.exe"
  557.       call:log "Downloading unzip tool.."
  558.       rem Original source: http://stahlworks.com/dev/unzip.exe
  559.       call:download_file "https://www.dropbox.com/s/gxf8d4bg0yyozdh/unzip.exe?dl=1" !unzip_tool!
  560.     )
  561.     if exist !unzip_tool! (
  562.       if exist "%~dp0\PSWindowsUpdate.zip" (
  563.         set local_pswu_module=1
  564.         set pswu_zip="%~dp0\PSWindowsUpdate.zip"
  565.         call:log "Local PSWindowsUpdate module found"
  566.       ) else (
  567.         set pswu_zip="%temp%\PSWindowsUpdate.zip"
  568.         call:log "Downloading PowerShell module 'PSWindowsUpdate'.."
  569.         rem Original source: https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/
  570.         call:download_file "https://www.dropbox.com/s/z61nlkfecmhabil/PSWindowsUpdate.zip?dl=1" !pswu_zip!
  571.       )
  572.       if exist !pswu_zip! (
  573.         set pswu_temp="%temp%\pswindowsupdate_content"
  574.         call:log "Uncompressing module archive.."
  575.         !unzip_tool! -oC !pswu_zip! -d !pswu_temp!>nul
  576.         if exist !pswu_temp! (
  577.           call:log "Moving module files to PowerShell modules directory.."
  578.           if exist !pswu_distr_path! (rmdir !pswu_distr_path! /s /q>nul)
  579.           move /y "!pswu_temp!\PSWindowsUpdate" !ps_modules_dir!>nul
  580.           if "!local_unzip_tool!" NEQ "1"  (del /f !unzip_tool!>nul)
  581.           if "!local_pswu_module!" NEQ "1" (del /f !pswu_zip!>nul)
  582.           rmdir !pswu_temp! /s /q>nul
  583.           if exist "!pswu_distr_path!\Hide-WUUpdate.ps1" (
  584.             call:log "'PSWindowsUpdate' module for PowerShell installed" "Installation complete"
  585.             set result=100
  586.             timeout /t 2 /nobreak>nul & tskill powershell>nul 2>&1 & timeout /t 2 /nobreak>nul
  587.           ) else (
  588.             call:log "Failure: Installation of 'PSWindowsUpdate' module failed - files in !pswu_distr_path! not found" "Installation failed"
  589.           )
  590.         )
  591.       )
  592.     )
  593.   )
  594.   exit /b
  595.  
  596. :uninstall_update
  597.   set kb_id=%~1
  598.   rem Remove update
  599.   call:log "Uninstalling KB%kb_id%.."
  600.   start /wait wusa /uninstall /norestart /quiet /kb:%kb_id%
  601.   if %errorlevel%==2359303 call:log "Update KB%kb_id% is not installed"
  602.   if %errorlevel%==1223 call:log "Uninstall cancelled"
  603.   if %errorlevel%==3010 call:log "Update KB%kb_id% UNINSTALLED successfully"
  604.   rem Add all updates IDs to single string variable (',' is delimiter)
  605.   set UpdatesList=%UpdatesList%KB%kb_id%,
  606.   exit /b
  607.  
  608. :disable_updates
  609.   rem Adding update to Windows Update exceptions (hide update) using PowerShell
  610.   if [!UpdatesList!] EQU [] (
  611.     call:log "Failure: update list is empty. To add update IDs to block list, please uninstall update(s) prior to running this script" "Error"
  612.     exit /b
  613.   )
  614.   rem Remove last (',') char
  615.   set UpdatesListForDisabling=!UpdatesList:~0,-1!
  616.   call:install_pswu_module
  617.   if %result%==100 (
  618.     call:log "Disable updates: !UpdatesListForDisabling!.."
  619.     powershell -ExecutionPolicy RemoteSigned -NoLogo -Noninteractive -Command "Import-Module PSWindowsUpdate; try { Hide-WUUpdate -KBArticleID !UpdatesListForDisabling! -Confirm:$false; exit 100; } catch { exit 0; }">nul 2>&1
  620.     if !errorlevel!==100 (
  621.       call:log "Updates are successfully DISABLED"
  622.     ) else (
  623.       call:log "Failure: unable to disable updates. Please update your PowerShell or install 'PSWindowsUpdate' PowerShell module" "Error"
  624.     )
  625.   )
  626.   exit /b
  627.  
  628. :block_route
  629.   set REDIRECT=0.0.0.0
  630.   set ip_addr=%~1
  631.   call:log "Blocking %ip_addr%"
  632.   route -p ADD %ip_addr% MASK 255.255.255.255 %REDIRECT%>nul 2>&1
  633.   rem Adding all addresses to single string variable (',' is delimiter)
  634.   set FirewallIPlist=%FirewallIPlist%%ip_addr%,
  635.   exit /b
  636.  
  637. :block_routes_with_firewall
  638.   if [!FirewallIPlist!] EQU [] (
  639.     call:log "Failure: empty IP list. For adding IP to firewall block list, please block IP by route first" "Error"
  640.     exit /b
  641.   )
  642.   if exist %SystemRoot%\System32\netsh.exe (
  643.     set FirewallRuleName=Remove MS Telemetry and Annoyances
  644.     rem Removing existing rule(s), adding new rule(s), and check that it exists.
  645.     netsh advfirewall firewall delete rule name="!FirewallRuleName!">nul
  646.     netsh advfirewall firewall add rule name="!FirewallRuleName!" dir=out action=block remoteip=!FirewallIPlist! interfacetype=any>nul
  647.     netsh advfirewall firewall show rule name="!FirewallRuleName!">nul
  648.     if %errorlevel% EQU 0 (
  649.       call:log "IP addresses blocked with firewall rule '!FirewallRuleName!': '!FirewallIPlist:~0,-1!'"
  650.     ) else (
  651.       call:log "Cannot add '!FirewallRuleName!' firewall rule - maybe firewall service is disabled^?" "Error"
  652.     )
  653.   ) else (
  654.     call:log "Failure: Windows Firewall is not accessible ('netsh.exe' file does not exist)" "Error"
  655.   )
  656.   exit /b
  657.  
  658. :disable_task
  659.   set task_name=%~1
  660.   call:log "Disabling task %task_name%"
  661.   schtasks /Change /TN "%task_name%" /DISABLE>nul 2>&1
  662.   exit /b
  663.  
  664. :disable_service
  665.   set service_name=%~1
  666.   set errors_counter=0
  667.   call:log "Disabling service '%service_name%'"
  668.   sc query "%service_name%">nul
  669.   if %errorlevel% NEQ 1060 (
  670.     sc config "!service_name!" start= disabled>nul
  671.     if %errorlevel% NEQ 0 set /a errors_counter=errors_counter+1
  672.     sc stop "!service_name!">nul
  673.     if %errorlevel% NEQ 0 set /a errors_counter=errors_counter+1
  674.     if %errors_counter%==0 (
  675.       call:log "Service '!service_name!' has been disabled successfully."
  676.     )
  677.   ) else set /a errors_counter=errors_counter+1 & call:log "Service '!service_name!' is not installed"
  678.   exit /b
  679.  
  680. :add_to_hosts
  681.   set HOSTS=%SystemRoot%\system32\drivers\etc\hosts
  682.   set REDIRECT=0.0.0.0
  683.   set block_title=## Block MS telemetry domain names
  684.   set write_title=0
  685.   set host_name=%~1
  686.   if "%host_name%"=="--title--" (
  687.     set write_title=1
  688.     set host_name=%block_title%
  689.   )
  690.   find /C /I "%host_name%" %HOSTS%>nul
  691.   if %errorlevel% NEQ 0 (
  692.     attrib -r %HOSTS%>nul
  693.     if !write_title! EQU 1 (
  694.       echo.>>%HOSTS%
  695.       echo.>>%HOSTS%
  696.       echo %block_title%>>%HOSTS%
  697.     ) else (
  698.       echo %REDIRECT% %host_name%>>%HOSTS%
  699.       call:log "Blocking domain %host_name%"
  700.     )
  701.   ) else (
  702.     if !write_title! NEQ 1 (
  703.       call:log "Domain is already blocked: %host_name%"
  704.     )
  705.   )
  706.   exit /b
  707.  
  708. :end
  709.   call:title "The script will exit automatically in 60 seconds. Press any key to exit now."
  710.   timeout /t 60>nul 2>&1
  711.   endlocal & if %ExitOnComplete%==1 (exit)
  712. echo on
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand