Advertisement
aveyo

windows_gaming_steam_dota_fix - outdated!

Apr 21st, 2017
11,515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Winbatch 31.55 KB | None | 0 0
  1. @goto=init %~nx0
  2. :: Batch designed for Windows 10 - compatible with Windows 7
  3. ::----------------------------------------------------------------------------------------------------------------------------------
  4. :about %1:[0c = red-on-black: Batch was run as user, 0b = cyan-on-black Batch was run as admin]
  5. ::----------------------------------------------------------------------------------------------------------------------------------
  6. call :clearline 1
  7. call :color %1. "      ---------------------------------------------------------------------  "
  8. call :color %1. "     :                  WINDOWS_GAMING_STEAM_DOTA_FIX V9.5                 : "
  9. call :color %1. "     :---------------------------------------------------------------------: "
  10. call :color %1. "     : -GameDVR -Xbox -GameBarPresenceWriter -FullscreenOpt AppCompatFlags : "
  11. call :color %1. "     : BCD + Network reset  SteamService /repair  Steam + DOTA cfg refresh : "
  12. call :color %1. "     : Undo script: https://pastebin.com/c4efe7gb                          : "
  13. call :color %1. "     :                                                                     : "
  14. call :color %1. "     : Press Alt+F4 to cancel                    Always run latest version : "
  15. call :color %1. "      ---------------------------------------------------------------------  "
  16. call :color %1. " "
  17. exit/b
  18.  
  19. ::----------------------------------------------------------------------------------------------------------------------------------
  20. :main [ Batch main function ]
  21. ::----------------------------------------------------------------------------------------------------------------------------------
  22. title AveYo's WINDOWS GAMING + STEAM + DOTA FIX
  23. color 07
  24. call :about 0b
  25. ::timeout /t 10
  26. set "steam_dota=SteamService,Steam_refresh,Dota_cfg"
  27. set "all_choices=AMD_Nvidia_DVR,GameDVR,GameBar,Xbox,Fullscreen_optimizations,AppCompatFlags,BCD_reset,Network_reset,%steam_dota%"
  28. set "def_choices=AMD_Nvidia_DVR,GameDVR,GameBar,Fullscreen_optimizations,AppCompatFlags,BCD_reset,Network_reset,%steam_dota%"
  29. call :choices MOD_CHOICES "%all_choices%" "%def_choices%" "Fix" 14 MidnightBlue Snow
  30. for %%o in (%all_choices%) do set "%%o="  &rem undefine all initial choices
  31. for %%o in (%MOD_CHOICES%) do set "%%o=1" &rem then redefine selected ones to 1
  32. :: export choices to registry
  33. if defined MOD_CHOICES reg add "HKCU\Environment" /v "Fix choices" /t REG_SZ /d "%MOD_CHOICES%" /f >nul 2>nul
  34. set "CHOICES=%MOD_CHOICES%"
  35.  
  36. set "ten=1" & ver | find "10." > nul
  37. if errorlevel 1 set "ten="
  38.  
  39. if not defined AMD_Nvidia_DVR goto skip_AMD_Nvidia_DVR
  40. ::----------------------------------------------------------------------------------------------------------------------------------
  41. call :mcolor 07 " Disabling " 70 " AMD DVR / Nvidia GFE / ShadowPlay " 07. " to prevent crashes, stutters and fps loss.. "
  42. :: amd dvr options and hotkeys
  43. set "regkey=SOFTWARE\AMD\DVR"
  44. set "options=CustomOverlayEnabled DesktopRecordingEnabled DvrEnabled InstantReplayEnabled RecordPerfUI RigInfoOverlayEnabled"
  45. set "hotkey1=SaveInstantReplayHotkey TakeScreenshotHotkey ToggleCameraHotkey ToggleDvrRecordingHotkey ToggleDvrToolbarHotkey"
  46. set "hotkey2=ToggleMicrophoneHotkey ToggleRsHotkey ToggleRsPerfRecordingHotkey ToggleRsPerfUiHotkey ToggleStreamingHotkey"
  47. for %%a in (HKCU HKLM) do for %%B in (32 64) do (
  48. for %%. in (%options%) do reg add "%%a\%regkey%" /v "%%." /t REG_DWORD /d 0 /f /reg:%%B
  49. for %%. in (%hotkey1% %hotkey2%) do reg add "%%a\%regkey%" /v "%%." /d "none" /f /reg:%%B
  50. ) >nul 2>nul
  51. :: amd dvr task disable and block
  52. schtasks /Change /TN "StartDVR" /DISABLE >nul 2>nul
  53. set "tasks=%SystemRoot%\System32\Tasks"
  54. if exist "%tasks%\StartDVR" (
  55. pushd "%tasks%"
  56. copy /y StartDVR StartDVR.bak
  57. del /f /q StartDVR
  58. mkdir StartDVR
  59. icacls StartDVR /deny "Everyone:(OI)(CI)W"
  60. popd
  61. ) >nul 2>nul
  62. :: amd dvr startup entry
  63. set "amddvr=C:\Program Files\AMD\CNext\CNext\amddvr.exe"
  64. for %%a in (HKCU HKLM) do reg delete "%%a\Software\Microsoft\Windows\CurrentVersion\Run" /v "%amddvr%" /f >nul 2>nul
  65. :: amd dvr / relive / telemetry executable block (amd force relive to run even if not selected as an install option)
  66. call :BlockExecution "amddvr amdow"
  67. :: amd disable overclock
  68. taskkill /im RadeonSettings.exe >nul 2>nul
  69. reg delete HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000 /v PP_CNEscapeInput /f >nul 2>nul
  70. ::schtasks /Change /TN "StartCN" /DISABLE >nul 2>nul
  71. set "regkey=HKCU\SOFTWARE\AMD\CN"
  72. reg add "%regkey%" /v "EulaAccepted" /d "False" /f >nul 2>nul
  73. reg add "%regkey%" /v "OverclockEnabled" /t REG_DWORD /d 0 /f >nul 2>nul
  74. ::reg add "%regkey%\Performance" /v "RecordInterval" /t REG_DWORD /d 120 /f >nul 2>nul
  75. reg add "%regkey%\ANALYTICS" /v "AnalyticsUploadDays" /d "3652" /f >nul 2>nul
  76. set "regkey=HKCU\Software\ATI\ACE\Settings\Runtime"
  77. reg add "%regkey%\Platform\AMDOverDrive" /v "EULA_Accepted" /d "False" /f >nul 2>nul
  78. reg add "%regkey%\Graphics\OverDrive5" /v "OverclockEnabled_DEF" /d "False" /f >nul 2>nul
  79. :: nvidia gfe / shadowplay / telemetry executable block (nvidia restores disabled services to force their crap to run)
  80. call :BlockExecution "nvstreamer NvTelemetryContainer NvContainer" &rem nvnodejslauncher NVNetworkService
  81. :skip_AMD_Nvidia_DVR
  82.  
  83. if not defined GameDVR goto skip_GameDVR
  84. ::----------------------------------------------------------------------------------------------------------------------------------
  85. call :mcolor 07 " Disabling " 70 " Windows Game DVR " 07. " to prevent stutters and fps loss.. "
  86. (
  87. reg add "HKCU\Software\Microsoft\GameBar" /v "AllowAutoGameMode" /t REG_DWORD /d "0" /f
  88. reg add "HKCU\Software\Microsoft\GameBar" /v "ShowStartupPanel" /t REG_DWORD /d "0" /f
  89. reg add "HKCU\Software\Microsoft\GameBar" /v "UseNexusForGameBarEnabled" /t REG_DWORD /d "0" /f
  90. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AppCaptureEnabled" /t REG_DWORD /d "0" /f
  91. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AudioCaptureEnabled" /t REG_DWORD /d "0" /f
  92. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "CursorCaptureEnabled" /t REG_DWORD /d "0" /f
  93. reg add "HKCU\System\GameConfigStore" /v "GameDVR_Enabled" /t REG_DWORD /d "0" /f
  94. reg add "HKLM\Software\Policies\Microsoft\Windows\GameDVR" /v "AllowgameDVR" /t REG_DWORD /d "0" /f
  95. ) >nul 2>nul
  96. call :BlockExecution "bcastdvr GamePanel"
  97. :skip_GameDVR
  98.  
  99. if not defined Xbox goto skip_Xbox
  100. ::----------------------------------------------------------------------------------------------------------------------------------
  101. call :mcolor 07 " Disabling " 70 " Xbox " 07. " to prevent stutters and fps loss.. "
  102. (
  103. reg add "HKLM\System\CurrentControlSet\Services\xbgm" /v "Start" /t REG_DWORD /d "4" /f
  104. schtasks /Change /TN "Microsoft\XblGameSave\XblGameSaveTask" /DISABLE
  105. schtasks /Change /TN "Microsoft\XblGameSave\XblGameSaveTaskLogon" /DISABLE
  106. sc config XblAuthManager start= disabled
  107. sc config XblGameSave start= disabled
  108. sc config XboxGipSvc start= disabled
  109. sc config XboxNetApiSvc start= disabled
  110. ) >nul 2>nul
  111. :skip_Xbox
  112.  
  113. if not defined GameBar goto skip_GameBar
  114. ::----------------------------------------------------------------------------------------------------------------------------------
  115. call :mcolor 07 " Disabling " 70 " GameBarPresenceWriter " 07. " to prevent micro-stutters.. "
  116. rem call :BlockExecution "GameBarPresenceWriter"
  117. set "regkey=Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter"
  118. call :reg_takeownership "HKLM\SOFTWARE\%regkey%" Administrators recursive
  119. call :reg_takeownership "HKLM\SOFTWARE\WOW6432Node\%regkey%" Administrators recursive
  120. reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f /reg:64 >nul 2>nul
  121. reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f /reg:32 >nul 2>nul
  122. :skip_GameBar
  123.  
  124. if not defined Fullscreen_optimizations goto skip_Fullscreen_optimizations
  125. ::----------------------------------------------------------------------------------------------------------------------------------
  126. call :mcolor 07 " Disabling " 70 " Fullscreen so-called optimizations " 07. " to prevent stutters and fps loss .. "
  127. set "COMPATFLAGS=~ DISABLEDXMAXIMIZEDWINDOWEDMODE"
  128. :: Query programs with AppCompatFlags already set and override them
  129. set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" &set "foropts="usebackq delims=""
  130. for %%a in (HKCU HKLM) do for %%B in (32 64) do (
  131. for /f %foropts% %%s in (`reg query "%%a\%regkey%" /reg:%%B 2^>nul ^| find "\" ^| find /i ".exe"`) do call :Filter %%a %%B "%%s" P
  132. )
  133. :: Get current user sid with vmic
  134. for /f "usebackq delims= " %%s in (`wmic useraccount where "name='%username%'" get sid ^| find "S-"`) do set "sid=%%s"
  135. :: Query bam service ( .i. microsoft... ) for previously executed programs, filter out built-in ones and add AppCompatFlags
  136. set "regkey=HKLM\SYSTEM\CurrentControlSet\Services\bam\UserSettings\%sid%"
  137. for /f %foropts% %%s in (`reg query "%regkey%" 2^>nul ^| find /i ".exe"`) do for %%a in (HKCU HKLM) do for %%B in (32 64) do (
  138. call :Filter %%a %%B "%%s" N
  139. )
  140. :skip_Fullscreen_optimizations
  141.  
  142. if not defined AppCompatFlags goto skip_AppCompatFlags
  143. ::----------------------------------------------------------------------------------------------------------------------------------
  144. call :mcolor 07 " Disabling " 70 " AppCompatFlags " 07. " to reduce annoyances and prevent crashes.. "
  145. set "regkey=Software\Policies\Microsoft\Windows\AppCompat"
  146. for %%a in (HKCU HKLM) do (
  147. reg add "%%a\%regkey%" /v "DisablePCA" /t REG_DWORD /d 1 /f
  148. reg add "%%a\%regkey%" /v "DisableUAR" /t REG_DWORD /d 1 /f
  149. reg add "%%a\%regkey%" /v "AITEnable" /t REG_DWORD /d 0 /f
  150. ) >nul 2>nul
  151. :: set conservative tdr limits
  152. set "regkey=HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers"
  153. (
  154. reg add "%regkey%" /v TdrLevel /t REG_DWORD /d 0x3 /f
  155. reg add "%regkey%" /v TdrDelay /t REG_DWORD /d 0xa /f
  156. reg add "%regkey%" /v TdrDdiDelay /t REG_DWORD /d 0xa /f
  157. reg add "%regkey%" /v TdrLimitCount /t REG_DWORD /d 0xa /f
  158. reg add "%regkey%" /v TdrLimitTime /t REG_DWORD /d 0x12c /f
  159. ) >nul 2>nul
  160. :: clear event logs for applications
  161. wevtutil.exe cl "Application" >nul 2>nul
  162. :skip_AppCompatFlags
  163.  
  164. if not defined BCD_reset goto skip_BCD_reset
  165. ::----------------------------------------------------------------------------------------------------------------------------------
  166. call :mcolor 07 " Resetting " 70 " BCD " 07. " to prevent crashes and VAC false-positives.. "
  167. for %%s in ("" " {default}" " {current}") do (
  168. bcdedit /deletevalue%%~s nointegritychecks
  169. bcdedit /deletevalue%%~s loadoptions
  170. bcdedit /debug%%~s off
  171. bcdedit /deletevalue%%~s nx
  172. bcdedit /set%%~s bootstatuspolicy ignoreallfailures
  173. ) >nul 2>nul
  174. :skip_BCD_reset
  175.  
  176. if not defined Network_reset goto skip_Network_reset
  177. ::----------------------------------------------------------------------------------------------------------------------------------
  178. call :mcolor 07 " Resetting " 70 " Network " 07. " to prevent conectivity issues.. "
  179. rem netsh advfirewall reset
  180. (
  181. ipconfig /flushdns
  182. nbtstat -R
  183. nbtstat -RR
  184. netsh int ipv4 reset
  185. netsh int ipv6 reset
  186. netsh winsock reset
  187. ) >nul 2>nul
  188. :skip_Network_reset
  189.  
  190. :: Generic windows gaming fixes end here, Steam and Dota fixes below
  191.  
  192. if not defined SteamService if not defined Steam_refresh if not defined Dota_cfg goto done
  193. ::----------------------------------------------------------------------------------------------------------------------------------
  194. call :mcolor 0e " You can press " e0 " ALT+F4 " 0e. " now if you don't need to reset STEAM and DOTA cfg .. "
  195. timeout /t 10
  196. call :clearline 3
  197. call :set_steam
  198. call :set_dota
  199. echo.
  200. echo  STEAM = %STEAMDATA%
  201. echo  DOTA2 = %DOTA%
  202. taskkill /t /f /im steam.exe >nul 2>nul
  203. :: disabling steam start with windows
  204. reg add "HKCU\Software\Valve\Steam" /v "AlreadyRetriedOfflineMode" /t REG_DWORD /d 1 /f >nul 2>nul
  205. reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "Steam" /f >nul 2>nul
  206. :: disabling steam and dota fullscreen so-called optimization and set dpi scaling to application..
  207. set "COMPATFLAGS=~ DISABLEDXMAXIMIZEDWINDOWEDMODE HIGHDPIAWARE"
  208. set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
  209. for %%. in ("%STEAMPATH%\Steam.exe" "%DOTA%\bin\win64\dota2.exe" "%DOTA%\bin\win32\dota2.exe") do (
  210. for %%a in (HKCU HKLM) do for %%B in (32 64) do reg delete "%%a\%regkey%" /v "%%~." /f /reg:%%B
  211. rem for %%B in (32 64) do reg add "HKCU\%regkey%" /v "%%~." /t REG_SZ /d "%COMPATFLAGS%" /f /reg:%%B
  212. ) >nul 2>nul
  213. :: reseting steam and dota image file execution + disabling sehop (can add for all programs by uncommenting :AppCompatFlags section)
  214. set "exes=Steam.exe steamwebhelper.exe GameOverlayUI.exe dota2.exe"
  215. set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
  216. for %%a in (%exes%) do for %%B in (32 64) do (
  217. reg delete "%regkey%\%%a" /va /f /reg:%%B
  218. reg add "%regkey%\%%a" /v "DisableExceptionChainValidation" /t REG_DWORD /d 1 /f /reg:%%B
  219. ) >nul 2>nul
  220. :: removing firewall rules
  221. for %%. in ("dota2" "Dota 2" "Steam" "Steam Web Helper") do netsh advfirewall firewall delete rule name=%%. >nul 2>nul
  222.  
  223. if not defined SteamService goto skip_SteamService
  224. ::----------------------------------------------------------------------------------------------------------------------------------
  225. call :mcolor 07 " Repairing " 70 " SteamService " 07. " to prevent crashes.. "
  226. set "sservice=%CommonProgramFiles(x86)%\Steam\SteamService.exe" &set "sservice32=%CommonProgramFiles%\Steam\SteamService.exe"
  227. if exist "%STEAMPATH%\bin\SteamService.exe" start "w" /MIN /WAIT "%STEAMPATH%\bin\SteamService.exe" /repair &goto skip_SteamService
  228. if exist "%sservice%" start "w" /MIN /WAIT "%sservice%" /repair &goto skip_SteamService
  229. if exist "%sservice32% "start "w" /MIN /WAIT "%sservice32%" /repair
  230. :skip_SteamService
  231.  
  232. if not defined Steam_refresh goto skip_Steam_refresh
  233. ::----------------------------------------------------------------------------------------------------------------------------------
  234. if not exist "%STEAMPATH%\steamapps\*.*" goto skip_Steam_refresh
  235. call :mcolor 07 " Resetting " 70 " Steam configuration " 07. " SteamApps Library is left untouched.. "
  236. cd/d "%STEAMPATH%"
  237. for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v "steam.exe"`) do del /f/q "%%a" >nul 2>nul
  238. for /f "tokens=*" %%a in ('dir /a:D /b ^| findstr /i /v steamapps') do del /f/q "%%a" >nul 2>nul &rmdir /s/q "%%a" >nul 2>nul
  239. set ".=%USERPROFILE%\AppData\Local\Steam"
  240. del /f/s/q "%.%" >nul 2>nul &rmdir /s/q "%.%" >nul 2>nul
  241. :skip_Steam_refresh
  242.  
  243. if not defined Dota_cfg goto skip_Dota_cfg
  244. ::----------------------------------------------------------------------------------------------------------------------------------
  245. call :set_steam & call :set_dota
  246. if not exist "%DOTA%\bin\win32\*.*" goto skip_Dota_cfg
  247. call :mcolor 07 " Resetting " 70 " DOTA configuration " 07. " Hotkeys + Settings are restored from Cloud.. "
  248. cd/d "%DOTA%\core"
  249. for %%a in (cfg scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
  250. cd/d "%DOTA%\dota"
  251. for %%a in (core scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
  252. for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v ".vpk"`) do del /f/q "%%a" >nul 2>nul
  253. del /f/q cfg\vide*.txt >nul 2>nul
  254. del /f/q cfg\*.vcfg >nul 2>nul
  255. set "vcfg=%DOTA%\dota\cfg\user_keys_default.vcfg"
  256. powershell -noprofile -c "[IO.File]::WriteAllText('%vcfg%',([IO.File]::ReadAllText('%~f0') -split ':vcfg\:.*\n')[1])"
  257. goto vcfg_done
  258. :vcfg: user_keys_default.vcfg
  259. "config"
  260. {
  261.     "bindings"
  262.     {
  263.         "\" "toggleconsole"
  264.         "F10" "return_to_tools_from_engine"
  265.     }
  266.  
  267.     "analogbindings"
  268.     {
  269.  
  270.     }
  271. }
  272. :vcfg:
  273. :vcfg_done
  274.  
  275. :: prevent launching the game before verification is finished + force exe refresh
  276. del /f/q "%DOTA%\bin\win64\dota2.exe" >nul 2>nul
  277. del /f/q "%DOTA%\bin\win32\dota2.exe" >nul 2>nul
  278. del /f/q "%DOTA%\bin\vidcfg.bin" >nul 2>nul
  279. echo  - removing old crash dump files..
  280. del /f/q "%DOTA%\bin\win64\*.mdmp" >nul 2>nul
  281. del /f/q "%DOTA%\bin\win32\*.mdmp" >nul 2>nul
  282. echo  - removing temporary files..
  283. rem (downloading temp workshop )
  284. for %%a in (downloading temp) do (
  285.  del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
  286.  rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
  287. )
  288. rem (downloading temp workshop )
  289. for %%a in (downloading temp) do (
  290.  takeown /f "%STEAMAPPS%\%%a" /r /d y >nul 2>nul
  291.  icacls "%STEAMAPPS%\%%a" /reset /t /q >nul 2>nul
  292.  del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
  293.  rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
  294. )
  295.  
  296. ::----------------------------------------------------------------------------------------------------------------------------------
  297. if not exist "%STEAMPATH%\Steam.exe" goto skip_Dota_cfg
  298. call :mcolor 07 " Reloading " 70 " Steam " 07. " - login to continue.. "
  299. echo  - verification of DOTA files will be done automatically on second run..
  300. set launchoptions= -console -forceservice -tcp +app_set_update_flag 570 1 +app_mark_validation 570 1 +app_start_validation 570 1
  301. start "w" "%STEAMPATH%\Steam.exe" %launchoptions% -applaunch 570
  302. timeout /t 20 >nul
  303. echo  - adding Steam shortcut with launch options on Desktop..
  304. set "L1=-silent -console -no-browser -nofriendsui -vrdisable -windowed -manuallyclearframes 0 -forceservice"
  305. set "L2=-nocrashmonitor -nocrashdialog -norepairfiles -noverifyfiles -skipstreamingdrivers +\"@AllowSkipGameUpdate 1 -"
  306. set "pslnk=$lnk=(New-Object -comObject WScript.Shell).CreateShortcut(\"$env:userprofile\Desktop\Steam_tweak.lnk\");"
  307. powershell -c "%pslnk%;$lnk.TargetPath=\"${env:ProgramFiles(x86)}\Steam\Steam.exe\";$lnk.Arguments='%L1% %L2%';$lnk.Save();"
  308. :skip_Dota_cfg
  309.  
  310. :done
  311. ::----------------------------------------------------------------------------------------------------------------------------------
  312. call :mcolor b0 " DONE " 0b " Some changes will take effect after the next PC restart "
  313. timeout /t 12 >nul
  314. exit
  315.  
  316. ::----------------------------------------------------------------------------------------------------------------------------------
  317. :: Utility functions
  318. ::----------------------------------------------------------------------------------------------------------------------------------
  319. :BlockExecution %1:[executable names without extension, like "bcastdvr GamePanel" ]
  320. set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
  321. for %%a in (%~1) do for %%B in (32 64) do (
  322.  reg add "%regkey%\%%a.exe" /v Debugger /t REG_SZ /d "%windir%\System32\systray.exe" /f /reg:%%B
  323. ) >nul 2>nul
  324. exit/b
  325.  
  326. :Filter %1:[HKCU or HKLM] %2:[32 or 64] %3:[string from reg query] %4:[P = keep path, N = just name]
  327. set "rq=%~3"
  328. set "rq=%rq:    =%"
  329. call set "rv=%%rq:*REG_=%%"
  330. call set "rv=%%rq:REG_%rv%=%%"
  331. if "%4"=="P" for %%s in ("%rv%") do call :AppCompatFlags %~1 %~2 "%%~s" %~4
  332. if "%4"=="N" for %%s in ("%rv%") do (
  333.  if /i "%%~nxs"=="conhost.exe" exit/b
  334.  if /i "%%~nxs"=="cmd.exe" exit/b
  335.  if /i "%%~nxs"=="powershell.exe" exit/b
  336.  if exist "%windir%\system32\%%~nxs" exit/b
  337.  if exist "%windir%\%%~nxs" exit/b
  338.  call :AppCompatFlags %~1 %~2 "%%~nxs" %~4
  339. )
  340. exit/b
  341.  
  342. :AppCompatFlags %1:[HKCU or HKLM] %2:[32 or 64] %3:[string from :FilterPrograms] %4:[P = keep path, N = just name]
  343. if "%~1%~2"=="HKCU32" echo   %~3 &rem there are several reg add operations, so only spew program name once
  344. set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
  345. reg add "%~1\%regkey%" /v "%~3" /t REG_SZ /d "%COMPATFLAGS%" /f /reg:%~2 >nul 2>nul
  346. :: uncomment lines below to also disable sehop for all programs previously executed
  347. rem set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
  348. rem if "%4"=="N" reg add "%regkey%\%%~3" /v "DisableExceptionChainValidation" /t REG_DWORD /d 1 /f >nul 2>nul
  349. exit/b
  350.  
  351. :reg_takeownership [USAGE] call :reg_takeownership "HKLM\MyKey" [OPTIONAL] "Administrators" recursive
  352. if not defined ps_RegTakeOwnership for %%s in (
  353. "$dll0='[DllImport(''ntdll.dll'')]public static extern int RtlAdjustPrivilege(ulong a,bool b,bool c,ref bool d);';"
  354. "$nt=Add-Type -Member $dll0 -Name NtDll -PassThru; foreach($i in @(9,17,18)){$null=$nt::RtlAdjustPrivilege($i,1,0,[ref]0)};"
  355. "function Reg_TakeOwnership { param($hive, $key, $own, $inherit=$false);"
  356. " $reg=[Microsoft.Win32.Registry]::$hive.OpenSubKey($key,'ReadWriteSubTree','TakeOwnership');"
  357. " $acl=New-Object System.Security.AccessControl.RegistrySecurity; $acl.SetOwner($own); $reg.SetAccessControl($acl);"
  358. " $acl.SetAccessRuleProtection($false,$false);$reg.SetAccessControl($acl);"
  359. " $reg=$reg.OpenSubKey('','ReadWriteSubTree','ChangePermissions'); if($inherit){"
  360. " $rule=New-Object System.Security.AccessControl.RegistryAccessRule($own,'FullControl','ContainerInherit','None','Allow');"
  361. " $acl.ResetAccessRule($rule); $reg.SetAccessControl($acl);} }; $rk=$regkey -split '\\\\',2; $key=$rk[1];"
  362. "switch -regex ($rk[0]) { '[mM]'{$HK='LocalMachine'};'[uU]'{$HK='CurrentUser'}; default {$HK='ClassesRoot'}; }; $HK; $key;"
  363. "if($user -eq ''){$user='Administrators'}; [System.Security.Principal.NTAccount]$owner=$user; $rcsv=($recursive -ne '');"
  364. "Reg_TakeOwnership $HK $key $owner $true; if($rcsv){$r=[Microsoft.Win32.Registry]::$HK.OpenSubKey($key);"
  365. "foreach($sk in $r.GetSubKeyNames()){$sk; try{ Reg_TakeOwnership $HK $($key+'\\'+$sk) $owner }catch{} }} "
  366. ) do call set "ps_RegTakeOwnership=%%ps_RegTakeOwnership%%%%~s"
  367. powershell.exe -c " $regkey='%~1';$user='%~2';$recursive='%~3'; %ps_RegTakeOwnership:'=\"%;" &exit/b by AveYo
  368.  
  369. :set_steam [OUTPUTS] STEAMPATH STEAMDATA STEAMID                                      AveYo : Override detection below if needed
  370. set "STEAMPATH=D:\Steam"
  371. if not exist "%STEAMPATH%\Steam.exe" call :reg_query STEAMPATH "HKCU\SOFTWARE\Valve\Steam" "SteamPath"
  372. set "STEAMDATA=" & if defined STEAMPATH for %%. in ("%STEAMPATH%") do set "STEAMPATH=%%~dpnx."
  373. if not exist "%STEAMPATH%\Steam.exe" call :end # Cannot find SteamPath in registry
  374. call :reg_query ACTIVEUSER "HKCU\SOFTWARE\Valve\Steam\ActiveProcess" "ActiveUser" & set/a "STEAMID=ACTIVEUSER" >nul 2>nul
  375. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  376. if not defined STEAMDATA for /f "delims=" %%. in ('dir "%STEAMPATH%\userdata" /b/o:d/t:w/s 2^>nul') do set "ACTIVEUSER=%%~dp."
  377. if not defined STEAMDATA for /f "delims=\" %%. in ("%ACTIVEUSER:*\userdata\=%") do set "STEAMID=%%."
  378. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  379. exit/b
  380.  
  381. :set_dota [OUTPUTS] STEAMAPPS DOTA CONTENT                                            AveYo : Override detection below if needed
  382. set "DOTA=D:\Games\steamapps\common\dota 2 beta\game"
  383. if exist "%DOTA%\dota\maps\dota.vpk" set "STEAMAPPS=%DOTA:\common\dota 2 beta=%" & exit/b
  384. set "libfilter=LibraryFolders { TimeNextStatsReport ContentStatsID }"
  385. if not exist "%STEAMPATH%\SteamApps\libraryfolders.vdf" call :end # Cannot find "%STEAMPATH%\SteamApps\libraryfolders.vdf"
  386. for /f usebackq^ delims^=^"^ tokens^=4 %%s in (`findstr /v "%libfilter%" "%STEAMPATH%\SteamApps\libraryfolders.vdf"`) do (
  387. if exist "%%s\steamapps\appmanifest_570.acf" if exist "%%s\steamapps\common\dota 2 beta\game\dota\pak01_*.vpk" set "libfs=%%s")
  388. set "STEAMAPPS=%STEAMPATH%\steamapps" & if defined libfs set "STEAMAPPS=%libfs:\\=\%\steamapps"
  389. if not exist "%STEAMAPPS%\common\dota 2 beta\game\dota\maps\dota.vpk" call :end # Missing "%STEAMAPPS%\common\dota 2 beta\game"
  390. set "DOTA=%STEAMAPPS%\common\dota 2 beta\game" & set "CONTENT=%STEAMAPPS%\common\dota 2 beta\content"
  391. exit/b
  392.  
  393. :unselect [USAGE] call :unselect choice variable[containing a list of choices separated by , comma]
  394. if not defined %~2 exit/b
  395. setlocal & call set "ops=%%%~2%%" & call set "ops=%%ops:,%~1=%%" & call set "ops=%%ops:%~1,=%%" & call set "ops=%%ops:%~1=%%"
  396. endlocal & call set "%~2=%ops%" & exit/b
  397.  
  398. :choices [USAGE] call :choices ResultVar "all,&choices" "default,choices" [OPTIONAL] "title" "textsize" "backcolor" "textcolor"
  399. (set "params=" & for %%s in (%*) do call set "params=%%params%% '%%~s'") & if not defined ps_? for /f delims^=^ eol^= %%. in (
  400. "function Choices($ov='', $all, $def, $n='Choices', [byte]$sz=12, $bc='MidnightBlue', $fc='Snow', $saved='HKCU:\Environment'){"
  401. "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $f=New-Object System.Windows.Forms.Form;"
  402. "$i=1; $j=1; $a=$all.split(','); $s=$def.split(','); $reg=(Get-ItemProperty $saved).$n; if($reg.length){$s=$reg.split(',') };"
  403. "function rst(){$cb | foreach{$_.Checked=0; if($s -contains $_.Text){$_.Checked=1 } } }; $f.Add_Shown({rst; $f.Activate()});"
  404. "$cb=@(); $a | foreach{$c=New-Object System.Windows.Forms.CheckBox;$c.Name=$i;$c.Text=$_;$c.MinimumSize='240,14';$c.AutoSize=1;"
  405. "$c.Margin='8,4,8,4';$c.Location='128,'+($sz*$i*2);$c.Font='Arial,'+$sz;$c.Cursor='Hand';$f.Controls.Add($c);$cb+=$c;$i++};"
  406. "$bt=@(); @('OK','Reset','Cancel') | foreach{$b=New-Object System.Windows.Forms.Button;  $b.Text=$_; $b.AutoSize=1;"
  407. "$b.Margin='0,0,72,20';$b.Location=''+(64*$j)+','+(($sz+1)*$i*2);$b.Font='Tahoma,'+$sz; $f.Controls.Add($b);$bt+=$b;$j+=2};"
  408. "$v=@(); $f.AcceptButton=$bt[0]; $f.CancelButton=$bt[2]; $bt[0].DialogResult=1; $bt[1].add_Click({$s=$def.split(',');rst});"
  409. "$f.Text=$n; $f.BackColor=$bc; $f.ForeColor=$fc; $f.StartPosition=4; $f.AutoSize=1; $f.AutoSizeMode=0; $f.FormBorderStyle=3;"
  410. "$f.MaximizeBox=0; $r=$f.ShowDialog(); if($r -eq 1){$cb | foreach{if($_.Checked){$v+=$_.Text}}; $val=$v -join ',';"
  411. "$null=New-ItemProperty -Path $saved -Name $n -Value $val -Force; return $val } }") do set "/=%%~." &call set "ps_?=%%/:" "=%%"
  412. (for /f "delims=" %%s in ('powershell -noprofile -c "%ps_?%; Choices %params%;"') do set "%1=%%s") &exit/b      snippet by AveYo
  413.  
  414. :reg_query [USAGE] call :reg_query ResultVar "HKCU\KeyName" "ValueName"
  415. (for /f "skip=2 delims=" %%s in ('reg query "%~2" /v "%~3" /z 2^>nul') do set ".=%%s" & call set "%~1=%%.:*)    =%%") & exit/b
  416.  
  417. ::----------------------------------------------------------------------------------------------------------------------------------
  418. :: Core functions
  419. ::----------------------------------------------------------------------------------------------------------------------------------
  420. :set_macros [OUTPUTS] %[BS]%=BackSpace %[CR]%=CarriageReturn %[GL]%=Glue/NonBreakingSpace %[DEL]%=DelChar %[DEL7]%=DelCharX7
  421. pushd "%TEMP%" & echo=WSH.Echo(String.fromCharCode(160))>` & for /f %%. in ('cscript //E:JScript //nologo `') do set "[GL]=%%."
  422. for /f %%. in ('echo prompt $H ^| cmd') do set "[BS]=%%." & for /f %%. in ('copy /z "%~dpf0" nul') do set "[CR]=%%."
  423. for /f "tokens=2 delims=1234567890" %%. in ('shutdown /?^|findstr /bc:"E"') do set "[TAB]=%%."
  424. set/p "=-"<nul>` &set "ECHOP=<nul set/p =%[BS]%" &set "[DEL]=%[BS]%%[GL]%%[BS]%" &call set "[DEL3]=%%[DEL]%%%%[DEL]%%%%[DEL]%%"
  425. set "[L]=-%[DEL]%\..\%[DEL3]%"&set "[J]=-%[DEL]%/..\%[DEL3]%"&set "[DEL6]=%[DEL3]%%[DEL3]%" &set "LABEL=echo. &call :color 70. "
  426. set "INFO=call :color b0 " INFO " &echo" & set "WARN=call :color e0 " WARN " &echo" & set "ERROR=call :color cf " ERROR " &echo"
  427. exit/b                                       &REM AveYo - :clearline and :color depend on this, initialize with call :set_macros
  428.  
  429. :clearline Number[how many lines above to delete - macro designed for Windows 10 but adjusted to work under 7 too]
  430. ( if not defined [DEL] call :set_macros ) &setlocal enableDelayedExpansion & set "[LINE]=%[CR]%" & set "[LINE7]=" & set "[COL]="
  431. for /f "skip=4 tokens=2 delims=:" %%a in ('mode con') do for %%c in (%%a) do if not defined [COL] call set "[COL]=%%c"
  432. set/a "[C7]=2+(%[COL]%+7)/8"&for /l %%i in (1,1,%[COL]%) do call set "[CLR]=%%[CLR]%%%[GL]%"&call set "[LINE]=%[DEL]%%%[LINE]%%"
  433. for /L %%a in (1,1,%[C7]%) do call set "[LINE7]=%%[LINE7]%%%[BS]%"
  434. ver | find "10." >nul & if errorlevel 1 (for /L %%i in (1,1,%1) do echo;%[TAB]%%[LINE7]%%[CLR]% & echo;%[TAB]%%[LINE7]% ) else (
  435. for /l %%i in (1,1,%1) do <nul set/p "=![LINE]!" )
  436. endlocal & exit/b                                                                                  &REM Usage: call :clearline 2
  437.  
  438. :color BgFg.[one or both of hexpair can be _ as defcolor, optional . use newline] text["text with spaces"]
  439. setlocal enableDelayedExpansion &set "bf=%~1"&set "tx=%~2"&set "tx=-%[BS]%!tx:\=%[L]%!"&set "tx=!tx:/=%[J]%!"&set "tx=!tx:"=\"!"
  440. set "bf=!bf: =!" &set "bc=!bf:~0,1!" &set "fc=!bf:~1,1!" &set "nl=!bf:~2,1!"&set "bc=!bc:_=%BackClr%!"&set "fc=!fc:_=%TextClr%!"
  441. pushd "%TEMP%" & findstr /p /r /a:!bc!!fc! "^^-" "!tx!\..\`" nul &<nul set/p "=%[DEL]%%[DEL6]%" &popd &if defined nl echo/%[GL]%
  442. endlocal & exit/b                    &REM AveYo - Usage: call :color fc Hello & call :color _c " fancy " & call :color cf. World
  443.  
  444. :mcolor BgFg. "only-quoted-text1" BgFg. "only-quoted-text2" etc.
  445. set "-mc~=" & for %%C in (%*) do if "%%C"=="%%~C" (call set "-mc~=%%-mc~%% & call :color %%C") else call set "-mc~=%%-mc~%% %%C"
  446. echo. %-mc~% & exit/b                                       &REM AveYo - Usage: call :mcolor fc "Hello" _c " fancy " cf. "World"
  447.  
  448. :end %1:Message[Delayed termination with status message - prefix with # to signal failure]
  449. echo. & if "%~1"=="#" ( %ERROR% %* & timeout /t 32 & exit ) else %INFO%  %* & timeout /t 20 & exit
  450.  
  451. ::------------------------------------------------------------------------------------------------------------------------------
  452. :init Console preferences                                           sets color table and prevents mouseclicks pausing the script
  453. ::------------------------------------------------------------------------------------------------------------------------------
  454. @echo off &setlocal &set "BackClr=0"&set "TextClr=7"&set "Columns=40" &set "Lines=120" &set "Buff=9999" &call :clearline 1 2>nul
  455. if not "%1"=="init" set/a SColors=0x%BackClr%%TextClr% & set/a WSize=Columns*256*256+Lines & set/a SBSize=Buff*256*256+Lines
  456. if not "%1"=="init" for %%. in ("HKCU\Console\init" ) do (
  457.  reg add %%. /v QuickEdit /d 0 /t REG_DWORD /f &reg add %%. /v CtrlKeyShortcutsDisabled /d 0 /t REG_DWORD /f
  458.  reg add %%. /v LineWrap /d 0 /t REG_DWORD /f &reg add %%. /v LineSelection /d 1 /t REG_DWORD /f
  459.  reg add %%. /v FaceName /d "Lucida Console" /t REG_SZ /f &reg add %%. /v FontSize /d 0xe0008 /t REG_DWORD /f
  460.  reg add %%. /v ScreenBufferSize /d %SBSize% /t REG_DWORD /f &reg add %%. /v WindowSize /d %WSize% /t REG_DWORD /f
  461.  reg add %%. /v ScreenColors /d %SColors% /t REG_DWORD /f &reg add HKCU\Console /v ForceV2 /d 1 /t REG_DWORD /f
  462.  reg add %%. /v ColorTable00 /d 0x000000 /t REG_DWORD /f &reg add %%. /v ColorTable08 /d 0x808080 /t REG_DWORD /f &REM black  dg
  463.  reg add %%. /v ColorTable01 /d 0x800000 /t REG_DWORD /f &reg add %%. /v ColorTable09 /d 0xff0000 /t REG_DWORD /f &REM blue   lb
  464.  reg add %%. /v ColorTable02 /d 0x008000 /t REG_DWORD /f &reg add %%. /v ColorTable10 /d 0x00ff00 /t REG_DWORD /f &REM green  lg
  465.  reg add %%. /v ColorTable03 /d 0x808000 /t REG_DWORD /f &reg add %%. /v ColorTable11 /d 0xffff00 /t REG_DWORD /f &REM cyan   lc
  466.  reg add %%. /v ColorTable04 /d 0x000080 /t REG_DWORD /f &reg add %%. /v ColorTable12 /d 0x0000ff /t REG_DWORD /f &REM red    lr
  467.  reg add %%. /v ColorTable05 /d 0x800080 /t REG_DWORD /f &reg add %%. /v ColorTable13 /d 0xff00ff /t REG_DWORD /f &REM purple lp
  468.  reg add %%. /v ColorTable06 /d 0x008080 /t REG_DWORD /f &reg add %%. /v ColorTable14 /d 0x00ffff /t REG_DWORD /f &REM yellow ly
  469.  reg add %%. /v ColorTable07 /d 0xc0c0c0 /t REG_DWORD /f &reg add %%. /v ColorTable15 /d 0xffffff /t REG_DWORD /f &REM lgray  wh
  470. ) >nul 2>nul
  471. rem if not "%1"=="init" ( cd/d %~dp0 & start "init" "%~f0" init & exit/b ) else goto main  &rem " Simple no admin self-restart "
  472. if "%1"=="init" goto main &rem " Admin self-restart flag found, jump to :main "
  473. reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto main || call :about 0c & echo  Requesting admin rights..
  474. powershell -noprofile -c "Start-Process cmd.exe -ArgumentList '/c \"%~f0\" init' -verb RunAs"
  475. exit
  476. ::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement