daily pastebin goal
34%
SHARE
TWEET

windows_gaming_steam_dota_fix

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