Advertisement
aveyo

windows_x_pro_update_policy

Mar 30th, 2018
2,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 13.67 KB | None | 0 0
  1. goto="init" /* %~nx0
  2. ::----------------------------------------------------------------------------------------------------------------------------------
  3. :about
  4. ::----------------------------------------------------------------------------------------------------------------------------------
  5. title Windows X Update Policy
  6. call :check_status
  7. echo.
  8. echo      ---------------------------------------------------------------------
  9. echo     :                 Windows X Update Policy Toggle v2.0                 :
  10. echo     :---------------------------------------------------------------------:
  11. echo     :   Pro: Set to notify before download and prevent driver installs    :
  12. echo     :             Just run this script again to toggle on/off             :
  13. echo     :                                                                     :
  14. echo     :                          Currently: %STATUS%%_%                     :
  15. echo     :                                                                     :
  16. echo     : Press Alt+F4 to cancel                    Always run latest version :
  17. echo      ---------------------------------------------------------------------
  18. echo.
  19. exit/b
  20. ::----------------------------------------------------------------------------------------------------------------------------------
  21. :main [ Batch main function ]
  22. ::----------------------------------------------------------------------------------------------------------------------------------
  23. call :about &timeout /t 10 &echo.
  24. if "%STATUS%"=="CUSTOM!" ( set "OP=delete" & set "NOP=/f >nul &rem" ) else set "OP=add" & set "NOP="
  25.  
  26. net stop wuauserv >nul 2>nul
  27.  
  28. :: Get current user sid with vmic
  29. for /f "usebackq delims= " %%s in (`wmic useraccount where "name='%username%'" get sid ^| find "S-"`) do set "sid=%%s"
  30.  
  31. :: Settings Accounts Sign-in options: use my sign-in info to automatically finish setting up my device after an update or restart
  32. set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\%sid%"
  33. reg %OP% "%key%" /v "OptOut" %NOP% /t REG_DWORD /d 0x1 /f >nul
  34. if "%STATUS%"=="DEFAULT" reg query "%key%" /v "OptOut" 2>nul
  35.  
  36. :: Disable Windows Update Delivery Optimization
  37. set "key=HKLM\Software\Policies\Microsoft\Windows\DeliveryOptimization"
  38. echo reg %OP% "%key%" /v "DODownloadMode" %NOP% /t REG_DWORD /d 0x0 /f >nul
  39. if "%STATUS%"=="DEFAULT" reg query "%key%" /v "DODownloadMode" 2>nul
  40.  
  41. :: Choose how updates are delivered 0=p2p update from MS only, 1=p2p update from PCs on LAN, 3=p2p update from PCs on the internet
  42. set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config"
  43. reg %OP% "%key%" /v "DownloadMode" %NOP% /t REG_DWORD /d 0x0 /f >nul
  44. reg %OP% "%key%" /v "DODownloadMode" %NOP% /t REG_DWORD /d 0x0 /f >nul
  45. if "%STATUS%"=="DEFAULT" reg query "%key%" 2>nul
  46.  
  47. :: UX and old style update settings - check but don't download, exclude drivers, no metered
  48. if "%STATUS%"=="DEFAULT" call :TakeKeyOwnership "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX" -y
  49. set "key1=HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings"
  50. set "key2=HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
  51. set "key3=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
  52. set keys="%key1%" "%key2%" "%key3%"
  53. :: Enable update management
  54. for %%k in (%keys%) do reg %OP% %%k /v "NoAutoUpdate" %NOP% /t REG_DWORD /d 0x0 /f >nul
  55. :: Enable updates 2=notify before download, 3=download and notify install, 4=download and schedule, 5=fully automatic
  56. for %%k in (%keys%) do reg %OP% %%k /v "AUOptions" %NOP% /t REG_DWORD /d 0x2 /f >nul
  57. :: Enable UX settings
  58. for %%k in (%keys%) do reg %OP% %%k /v "UxOption" %NOP% /t REG_DWORD /d 0x1 /f >nul
  59. for %%k in (%keys%) do reg %OP% %%k /v "IsConvergedUpdateStackEnabled" %NOP% /t REG_DWORD /d 0x1 /f >nul
  60. :: Active Hours enabled 08 - 23
  61. for %%k in (%keys%) do reg %OP% %%k /v "SetActiveHours" %NOP% /t REG_DWORD /d 0x0 /f >nul
  62. for %%k in (%keys%) do reg %OP% %%k /v "ActiveHoursEnd" %NOP% /t REG_DWORD /d 0x17 /f >nul 2>nul
  63. for %%k in (%keys%) do reg %OP% %%k /v "ActiveHoursStart" %NOP% /t REG_DWORD /d 0x8 /f >nul 2>nul
  64. :: Disable Windows Update Power Management from automatically wake up the system to install scheduled updates
  65. for %%k in (%keys%) do reg %OP% %%k /v "AUPowerManagement" %NOP% /t REG_DWORD /d 0x0 /f >nul 2>nul
  66. :: Do not download over metered connection
  67. for %%k in (%keys%) do reg %OP% %%k /v "AllowAutoWindowsUpdateDownloadOverMeteredNetwork" %NOP% /t REG_DWORD /d 0x0 /f >nul
  68. :: Include recommended updates
  69. for %%k in (%keys%) do reg %OP% %%k /v "IncludeRecommendedUpdates" %NOP% /t REG_DWORD /d 0x1 /f >nul
  70. :: Do not autoinstall minor updates
  71. for %%k in (%keys%) do reg %OP% %%k /v "AutoInstallMinorUpdates" %NOP% /t REG_DWORD /d 0x1 /f >nul
  72. :: Exclude drivers from updates
  73. for %%k in (%keys%) do reg %OP% %%k /v "ExcludeWUDriversInQualityUpdate" %NOP% /t REG_DWORD /d 0x1 /f >nul
  74. :: Hide Creators Update build is non the way add
  75. for %%k in (%keys%) do reg %OP% %%k /v "HideMCTLink" %NOP% /t REG_DWORD /d 0x1 /f >nul
  76. :: Defer updates
  77. for %%k in (%keys%) do reg %OP% %%k /v "DeferFeatureUpdatesPeriodInDays" %NOP% /t REG_DWORD /d 0x0 /f >nul
  78. for %%k in (%keys%) do reg %OP% %%k /v "DeferQualityUpdatesPeriodInDays" %NOP% /t REG_DWORD /d 0x0 /f >nul
  79. for %%k in (%keys%) do reg %OP% %%k /v "DeferUpgrade" %NOP% /t REG_DWORD /d 0x0 /f >nul
  80. :: Check frequency
  81. for %%k in (%keys%) do reg %OP% %%k /v "DetectionFrequency" %NOP% /t REG_DWORD /d 0xa /f >nul
  82. for %%k in (%keys%) do reg %OP% %%k /v "DetectionFrequencyEnabled" %NOP% /t REG_DWORD /d 0x1 /f >nul
  83. :: Schedule install every day 0=every day, 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday
  84. for %%k in (%keys%) do reg %OP% %%k /v "ScheduledInstallDay" %NOP% /t REG_DWORD /d 0x0 /f >nul
  85. :: Schedule install time 23pm
  86. for %%k in (%keys%) do reg %OP% %%k /v "ScheduledInstallTime" %NOP% /t REG_DWORD /d 0x17 /f >nul
  87. :: Remove shutdown with update options
  88. for %%k in (%keys%) do reg %OP% %%k /v "NoAUAsDefaultShutdownOption" %NOP% /t REG_DWORD /d 0x1 /f >nul
  89. for %%k in (%keys%) do reg %OP% %%k /v "NoAUShutdownOption" %NOP% /t REG_DWORD /d 0x0 /f >nul
  90. :: Don't autoreboot
  91. for %%k in (%keys%) do reg %OP% %%k /v "NoAutoRebootWithLoggedOnUsers" %NOP% /t REG_DWORD /d 0x1 /f >nul
  92. :: Longer reboot notification
  93. for %%k in (%keys%) do reg %OP% %%k /v "RebootRelaunchTimeout" %NOP% /t REG_DWORD /d 0x5a0 /f >nul
  94. for %%k in (%keys%) do reg %OP% %%k /v "RebootRelaunchTimeoutEnabled" %NOP% /t REG_DWORD /d 0x1 /f >nul
  95. :: Reboot warning
  96. for %%k in (%keys%) do reg %OP% %%k /v "RebootWarningTimeout" %NOP% /t REG_DWORD /d 0x5a0 /f >nul
  97. for %%k in (%keys%) do reg %OP% %%k /v "RebootWarningTimeoutEnabled" %NOP% /t REG_DWORD /d 0x1 /f >nul  
  98. :: Longer reschedule wait
  99. for %%k in (%keys%) do reg %OP% %%k /v "RescheduleWaitTime" %NOP% /t REG_DWORD /d 0x14 /f >nul
  100. for %%k in (%keys%) do reg %OP% %%k /v "RescheduleWaitTimeEnabled" %NOP% /t REG_DWORD /d 0x1 /f >nul
  101. :: More restart notifications
  102. for %%k in (%keys%) do reg %OP% %%k /v "RestartNotificationsAllowed" %NOP% /t REG_DWORD /d 0x1 /f >nul
  103. if "%STATUS%"=="DEFAULT" reg query "%key1%" 2>nul
  104.  
  105. :: Do you want Windows to download driver software 0=never ,1=always, 2=install if not found on my computer
  106. set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching"
  107. reg %OP% "%key%" /v "SearchOrderConfig" %NOP% /t REG_DWORD /d 0x2 /f >nul
  108. if "%STATUS%"=="DEFAULT" reg query "%key%" /v "SearchOrderConfig" 2>nul
  109.  
  110. :: Disable enhanced manufacturer icons
  111. set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Device Metadata"
  112. reg %OP% "%key%" /v "PreventDeviceMetadataFromNetwork" %NOP% /t REG_DWORD /d 0x0 /f >nul
  113. if "%STATUS%"=="DEFAULT" reg query "%key%" /v "PreventDeviceMetadataFromNetwork" 2>nul
  114.  
  115. :: Enable 'Give me updates for other Microsoft products when I update Windows'
  116. set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\7971f918-a847-4430-9279-4a52d1efe18d"
  117. reg %OP% "%key%" /v "RegisteredWithAU" %NOP% /t REG_DWORD /d 0x1 /f >nul
  118. if "%STATUS%"=="DEFAULT" reg query "%key%" /v "RegisteredWithAU" 2>nul
  119.  
  120. :: Disable Automatic Update of Speech Data
  121. if "%STATUS%"=="DEFAULT" call :TakeKeyOwnership "HKLM\SOFTWARE\Microsoft\Speech_OneCore" -y
  122. set "key=HKLM\SOFTWARE\Microsoft\Speech_OneCore\Preferences"
  123. reg %OP% "%key%\Preferences" /v "ModelDownloadAllowed" %NOP% /t REG_DWORD /d 0x0 /f >nul
  124. if "%STATUS%"=="DEFAULT" reg query "%key%\Preferences" /v "ModelDownloadAllowed" 2>nul
  125.  
  126. :: Smart multi-homed name resolution - prevent dns timeouts and leaks when using VPN
  127. set "key1=HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient"
  128. set "key2=HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters"
  129. reg %OP% "%key1%" /v "DisableSmartNameResolution" %NOP% /t REG_DWORD /d 0x1 /f >nul
  130. reg %OP% "%key2%" /v "DisableParallelAandAAAA" %NOP% /t REG_DWORD /d 0x1 /f >nul
  131. if "%STATUS%"=="DEFAULT" reg query "%key1%" /v "DisableSmartNameResolution" 2>nul
  132. if "%STATUS%"=="DEFAULT" reg query "%key2%" /v "DisableParallelAandAAAA" 2>nul
  133.  
  134. net start wuauserv >nul 2>nul
  135.  
  136. echo.
  137. call :check_status
  138.  
  139. :: Done!
  140. echo ---------------------------------------------------------------------
  141. if "%STATUS%"=="CUSTOM!" ( color 0c &echo  Update Policy now: CUSTOM! ) else color 0b &echo  Update Policy now: DEFAULT
  142. echo ---------------------------------------------------------------------
  143. echo.
  144. pause
  145. exit
  146.  
  147. ::----------------------------------------------------------------------------------------------------------------------------------
  148. :: Utility functions
  149. ::----------------------------------------------------------------------------------------------------------------------------------
  150. :check_status
  151. set "policykey=HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings"  
  152. call :reg_query "%policykey%" "AUOptions" UPDATE_POLICY
  153. if "[%UPDATE_POLICY%]"=="[0x2]" ( set "STATUS=CUSTOM!" ) else set "STATUS=DEFAULT"
  154. set "_=    " &if "%STATUS%"=="CUSTOM!" ( color 0c ) else color 0b
  155. exit/b
  156.  
  157. :TakeKeyOwnership %1:regpath[ex:"HKCU\Console"] %2:_recurse[optional, default:"-n", "-y"] %3:_sid[optional, default:"S-1-5-32-545"]
  158. rem $src=https://stackoverflow.com/questions/12044432/how-do-i-take-ownership-of-a-registry-key-via-powershell snippet-ized by AveYo
  159. set "s10=function TakeKeyOwnership { param($regp, $all, $owner); $recurse=($all -eq '-y'); $RP=($regp -split '\\',2); $key=$RP[1];"
  160. set "s11= switch -regex ($RP[0]) { 'HKLM|HKEY_LOCAL_MACHINE' {$HK='LocalMachine'};'HKCC|HKEY_CURRENT_CONFIG' {$HK='CurrentConfig'};"
  161. set "s12=  'HKCR|HKEY_CLASSES_ROOT' {$HK='ClassesRoot'};'HKU|HKEY_USERS' {$HK='Users'};'HKCU|HKEY_CURRENT_USER' {$HK='CurrentUser'}"
  162. set "s13= }; $rootKey=$HK; if ($owner -eq '') {$owner='S-1-5-32-545'}; [System.Security.Principal.SecurityIdentifier]$sid=$owner;"
  163. set "s14= $import='[DllImport("ntdll.dll")] public static extern int RtlAdjustPrivilege(ulong a, bool b, bool c, ref bool d);';"
  164. set "s15= $ntdll=Add-Type -Member $import -Name NtDll -PassThru; $privileges=@{ SeTakeOwnership=9; SeBackup=17; SeRestore=18 };"
  165. set "s16= foreach ($i in $privileges.Values) { $null=$ntdll::RtlAdjustPrivilege($i, 1, 0, [ref]0) };"
  166. set "s17= function Take-KeyPermissions { param($rootKey, $key, $sid, $recurse, $recurseLevel=0);"
  167. set "s18=  $regKey=[Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership');"
  168. set "s19=  $acl=New-Object System.Security.AccessControl.RegistrySecurity; $acl.SetOwner($sid); $regKey.SetAccessControl($acl);"
  169. set "s20=  $acl.SetAccessRuleProtection($false, $false); $regKey.SetAccessControl($acl);"
  170. set "s21=  if ($recurseLevel -eq 0) { $regKey=$regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions');"
  171. set "s22=  $rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,'FullControl','ContainerInherit','None','Allow');"
  172. set "s23=  $acl.ResetAccessRule($rule); $regKey.SetAccessControl($acl) };"
  173. set "s24=  if ($recurse) { foreach($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {"
  174. set "s25=    Take-KeyPermissions $rootKey ($key+'\'+$subKey) $sid $recurse ($recurseLevel+1) } };"
  175. set "s26= }; $ErrorActionPreference='Continue'; Take-KeyPermissions $rootKey $key $sid $recurse }"
  176. for /l %%# in (10,1,26) do call set "ps_TakeKeyOwnership=%%ps_TakeKeyOwnership%%%%s%%#:"=\"%%"
  177. powershell.exe -c "%ps_TakeKeyOwnership%; try { TakeKeyOwnership '%~1' '%~2' '%~3' } catch {}"
  178. exit/b
  179.  
  180. :reg_query %1:KeyName %2:ValueName %3:OutputVariable %4:other_options[example: "/reg:32"]
  181. setlocal & for /f "skip=2 delims=" %%s in ('reg query "%~1" /v "%~2" /z %4 2^>nul') do set "rq=%%s" & call set "rv=%%rq:*)    =%%"
  182. endlocal & call set "%~3=%rv%" & exit/b                          ||:i AveYo - Usage:" call :reg_query "HKCU\MyKey" "MyValue" MyVar "
  183.  
  184. ::----------------------------------------------------------------------------------------------------------------------------------
  185. :"init" [ Batch entry function ]
  186. ::----------------------------------------------------------------------------------------------------------------------------------
  187. @echo off & cls & setlocal & if "%1"=="init" shift &shift & goto :main &rem Admin self-restart flag found, jump to main
  188. reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto :main || call :about 0c & echo  Requesting admin rights..
  189. call cscript /nologo /e:JScript "%~f0" get_rights "%1" & exit
  190. ::----------------------------------------------------------------------------------------------------------------------------------
  191. */ // [ JScript functions ] all batch lines above are treated as a /* js comment */ in cscript
  192. function get_rights(fn) { var console_init_shift='/c start "init" "'+fn+'"'+' init '+fn+' '+WSH.Arguments(1);
  193.   WSH.CreateObject("Shell.Application").ShellExecute('cmd.exe',console_init_shift,"","runas",1); }
  194. if (WSH.Arguments.length>=1 && WSH.Arguments(0)=="get_rights") get_rights(WSH.ScriptFullName);
  195. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement