daily pastebin goal
69%
SHARE
TWEET

windows_gaming_steam_dota_fix

aveyo Apr 21st, 2017 (edited) 2,159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. goto="init" /* %~nx0
  2.  
  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. "      ---------------------------------------------------------------------  "
  9. call :color %1. "     :                  WINDOWS_GAMING_STEAM_DOTA_FIX V8.3                 : "
  10. call :color %1. "     :---------------------------------------------------------------------: "
  11. call :color %1. "     : -GameBarPresenceWriter -GameDVR -AppCompatFlags -ImageFileExecution : "
  12. call :color %1. "     : BCD + Network reset  SteamService /repair  Steam + DOTA cfg refresh : "
  13. call :color %1. "     : Undo script: https://pastebin.com/c4efe7gb                          : "
  14. call :color %1. "     :                                                                     : "
  15. call :color %1. "     :          [Warning] This will forcefuly close Steam + Games          : "
  16. call :color %1. "     : Press Alt+F4 to cancel                    Always run latest version : "
  17. call :color %1. "      ---------------------------------------------------------------------  "
  18. call :color %1. " "
  19. exit/b
  20.  
  21. ::----------------------------------------------------------------------------------------------------------------------------------
  22. :start [ Batch main function ]
  23. ::----------------------------------------------------------------------------------------------------------------------------------
  24. call :about 0b
  25. timeout /t 10
  26. call :clearline 1
  27. echo  Ignore STEAM and DOTA related messages if you just need Windows Gaming fixes
  28. call :set_steam
  29. call :set_dota
  30. echo  - STEAM = %STEAMDATA%
  31. echo  - DOTA2 = %DOTA%
  32. taskkill /t /f /im steam.exe >nul 2>nul
  33.  
  34. ::1 - stutters
  35. call :mcolor 07 " Disabling " 70 " GameBarPresenceWriter " 07. " to prevent micro-stutters.. "
  36. set "regkey=Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter"
  37. rem echo  - using TakeKeyOwnership snippet - 3rd param is sid [ex. S-1-5-32-544=Administrators, S-1-5-32-545=Users]  
  38. call :TakeKeyOwnership "HKLM\SOFTWARE\%regkey%" -y
  39. reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f >nul 2>nul  
  40. call :TakeKeyOwnership "HKLM\SOFTWARE\WOW6432Node\%regkey%" -y
  41. reg add "HKLM\SOFTWARE\WOW6432Node\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f >nul 2>nul
  42.  
  43. :: GameBar - alternative disable method
  44. rem call :mcolor 07 " Disabling " 70 " GameBar " 07. " to prevent micro-stutters.. "
  45. rem set "regkey=Microsoft\WindowsRuntime\ActivatableClassId\Windows.Media.Capture.Internal.AppCaptureShell"
  46. rem call :TakeKeyOwnership "HKLM\SOFTWARE\%regkey%" -y
  47. rem reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f >nul 2>nul  
  48. rem call :TakeKeyOwnership "HKLM\SOFTWARE\WOW6432Node\%regkey%" -y
  49. rem reg add "HKLM\SOFTWARE\WOW6432Node\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f >nul 2>nul
  50.  
  51. ::2 - stutters and fps loss
  52. call :mcolor 07 " Disabling " 70 " GameDVR and Xbox" 07. " to prevent stutters and fps loss.. "
  53. (
  54. reg add "HKCU\Software\Microsoft\GameBar" /v "AllowAutoGameMode" /t REG_DWORD /d "0" /f
  55. reg add "HKCU\Software\Microsoft\GameBar" /v "ShowStartupPanel" /t REG_DWORD /d "0" /f
  56. reg add "HKCU\Software\Microsoft\GameBar" /v "UseNexusForGameBarEnabled" /t REG_DWORD /d "0" /f
  57. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AppCaptureEnabled" /t REG_DWORD /d "0" /f
  58. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AudioCaptureEnabled" /t REG_DWORD /d "0" /f
  59. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "CursorCaptureEnabled" /t REG_DWORD /d "0" /f
  60. reg add "HKCU\System\GameConfigStore" /v "GameDVR_Enabled" /t REG_DWORD /d "0" /f
  61. reg add "HKLM\Software\Policies\Microsoft\Windows\GameDVR" /v "AllowgameDVR" /t REG_DWORD /d "0" /f
  62. reg add "HKLM\System\CurrentControlSet\Services\xbgm" /v "Start" /t REG_DWORD /d "4" /f
  63. sc config XblAuthManager start= disabled
  64. sc config XblGameSave start= disabled
  65. sc config XboxGipSvc start= disabled
  66. sc config XboxNetApiSvc start= disabled
  67. schtasks /Change /TN "Microsoft\XblGameSave\XblGameSaveTask" /Disable
  68. ) >nul 2>nul
  69.  
  70. ::3 crashes, vac false positives
  71. call :mcolor 07 " Resetting " 70 " BCD " 07. " to prevent crashes and VAC false-positives.. "
  72. rem bcdedit.exe /set {current} nx OptIn &rem AlwaysOn
  73. (
  74.  bcdedit /deletevalue nointegritychecks
  75.  bcdedit /deletevalue loadoptions
  76.  bcdedit /debug off
  77.  bcdedit /deletevalue nx
  78. ) >nul 2>nul
  79.  
  80. ::4 conectivity issues
  81. call :mcolor 07 " Resetting " 70 " Network " 07. " to prevent conectivity issues.. "
  82. rem netsh advfirewall reset
  83. (
  84.  ipconfig /flushdns
  85.  nbtstat -R
  86.  nbtstat -RR
  87.  netsh advfirewall firewall delete rule name="dota2"
  88.  netsh advfirewall firewall delete rule name="Dota 2"
  89.  netsh advfirewall firewall delete rule name="Steam"
  90.  netsh advfirewall firewall delete rule name="Steam Web Helper"
  91.  netsh int ipv4 reset
  92.  netsh int ipv6 reset
  93.  netsh winsock reset
  94. ) >nul 2>nul
  95.  
  96. ::5 crashes, vac false-positives
  97. call :mcolor 07 " Repairing " 70 " SteamService " 07. " to prevent crashes.. "
  98. set "sservice=%CommonProgramFiles(x86)%\Steam\SteamService.exe" &set "sservice32=%CommonProgramFiles%\Steam\SteamService.exe"
  99. if exist "%STEAMPATH%\bin\SteamService.exe" start "w" /MIN /WAIT "%STEAMPATH%\bin\SteamService.exe" /repair
  100. if not exist "%STEAMPATH%\bin\SteamService.exe" if exist "%sservice%" start "w" /MIN /WAIT "%sservice%" /repair
  101. if not exist "%STEAMPATH%\bin\SteamService.exe" if not exist "%sservice%" start "w" /MIN /WAIT "%sservice32%" /repair
  102.  
  103. ::6 - crashes, stutters and fps loss
  104. call :mcolor 07 " Resetting " 70 " AppCompatFlags " 07. " to prevent crashes, stutters and fps loss.. "
  105. echo  - disabling fullscreen optimization for Steam and DOTA..
  106. set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
  107. set "compatflags=~ DISABLEDXMAXIMIZEDWINDOWEDMODE"
  108. for %%a in (HKCU HKLM) do for %%B in (32 64) do (
  109.  reg add "%%a\%regkey%" /v "%STEAMPATH%\Steam.exe" /t REG_SZ /d "%compatflags%" /f /reg:%%B
  110.  reg add "%%a\%regkey%" /v "%STEAMPATH%\GameOverlayUI.exe" /t REG_SZ /d "%compatflags%" /f /reg:%%B
  111.  reg add "%%a\%regkey%" /v "%DOTA%\bin\win64\dota2.exe" /t REG_SZ /d "%compatflags%" /f /reg:%%B
  112.  reg add "%%a\%regkey%" /v "%DOTA%\bin\win32\dota2.exe" /t REG_SZ /d "%compatflags%" /f /reg:%%B
  113. ) >nul 2>nul
  114. set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant"
  115. set excl="%STEAMPATH%\Steam.exe"\0"%STEAMPATH%\GameOverlayUI.exe"\0
  116. set uded="%DOTA%\bin\win64\dota2.exe"\0"%DOTA%\bin\win32\dota2.exe"\0
  117. for %%a in (HKCU HKLM) do for %%B in (32 64) do (
  118.  reg add "%%a\%regkey%" /v "ExecutablesToExclude" /t REG_MULTI_SZ /d %excl%%uded% /f /reg:%%B
  119. ) >nul 2>nul
  120. for %%a in (HKCU HKLM) do for %%B in (32 64) do for %%z in (Persisted Store) do (
  121.  reg delete "%%a\%regkey%\%%z" /v "%STEAMPATH%\Steam.exe" /f /reg:%%B
  122.  reg delete "%%a\%regkey%\%%z" /v "%STEAMPATH%\GameOverlayUI.exe" /f /reg:%%B
  123.  reg delete "%%a\%regkey%\%%z" /v "%DOTA%\bin\win64\dota2.exe" /f /reg:%%B
  124.  reg delete "%%a\%regkey%\%%z" /v "%DOTA%\bin\win32\dota2.exe" /f /reg:%%B
  125. ) >nul 2>nul
  126.  
  127. ::7 crashes
  128. call :mcolor 07 " Resetting " 70 " ImageFileExecution " 07. " and disable sehop to prevent crashes.. "
  129. set "exes=Steam.exe steamwebhelper.exe GameOverlayUI.exe dota2.exe"
  130. set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
  131. for %%a in (%exes%) do for %%B in (32 64) do (
  132.  reg delete "%regkey%\%%a" /va /f /reg:%%B
  133.  reg add "%regkey%\%%a" /v "DisableExceptionChainValidation" /t REG_DWORD /d 1 /f /reg:%%B
  134. ) >nul 2>nul
  135. :: remove appverif & memory leak diag
  136. set "regkey=HKLM\Software\Microsoft\RADAR\HeapLeakDetection\DiagnosedApplications"
  137. for %%a in (%exes%) do for %%B in (32 64) do reg delete "%regkey%\%%a" /va /f /reg:%%B >nul 2>nul
  138. :: disable steam start with windows
  139. reg add "HKCU\Software\Valve\Steam" /v "AlreadyRetriedOfflineMode" /t REG_DWORD /d 1 /f >nul 2>nul
  140. reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "Steam" /f >nul 2>nul
  141.  
  142. rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem rem  
  143. call :mcolor 0e " You can press " e0 " ALT+F4 " 0e. " now if you don't need to reset STEAM and DOTA cfg .. "
  144. timeout /t 10
  145. call :clearline 4
  146.  
  147. ::8 crashes, conectivity
  148. call :mcolor 07 " Resetting " 70 " Steam configuration " 07. " SteamApps Library is left untouched.. "
  149. set ".=%USERPROFILE%\AppData\Local\Steam"
  150. del /f/s/q "%.%" >nul 2>nul &rmdir /s/q "%.%" >nul 2>nul
  151. cd/d "%STEAMPATH%"
  152. for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v "steam.exe"`) do del /f/q "%%a" >nul 2>nul
  153. 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
  154.  
  155. ::9 crashes, conectivity, performance
  156. call :mcolor 07 " Resetting " 70 " DOTA configuration " 07. " Hotkeys + Settings are restored from Cloud.. "
  157. cd/d "%DOTA%\core"
  158. for %%a in (cfg scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
  159. cd/d "%DOTA%\dota"
  160. for %%a in (core scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
  161. for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v ".vpk"`) do del /f/q "%%a" >nul 2>nul
  162. del /f/q cfg\vide*.txt >nul 2>nul
  163. del /f/q cfg\*.vcfg >nul 2>nul
  164. :: prevent launching the game before verification is finished + force exe refresh
  165. del /f/q "%DOTA%\dota\bin\win64\*.dll" >nul 2>nul
  166. del /f/q "%DOTA%\dota\bin\win32\*.dll" >nul 2>nul
  167. del /f/q "%DOTA%\bin\win64\dota2.exe" >nul 2>nul
  168. del /f/q "%DOTA%\bin\win32\dota2.exe" >nul 2>nul
  169. del /f/q "%DOTA%\bin\vidcfg.bin" >nul 2>nul
  170. echo  - removing old crash dump files..
  171. del /f/q "%DOTA%\bin\win64\*.mdmp" >nul 2>nul
  172. del /f/q "%DOTA%\bin\win32\*.mdmp" >nul 2>nul
  173. echo  - removing temporary files..
  174. rem (downloading temp workshop )
  175. for %%a in (downloading temp) do (
  176.  del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
  177.  rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
  178. )
  179. rem (downloading temp workshop )
  180. for %%a in (downloading temp) do (
  181.  takeown /f "%STEAMAPPS%\%%a" /r /d y >nul 2>nul
  182.  icacls "%STEAMAPPS%\%%a" /reset /t /q >nul 2>nul
  183.  del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
  184.  rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
  185. )
  186.  
  187. ::10 restart Steam and update DOTA
  188. call :mcolor 07 " Reloading " 70 " Steam " 07. " - login to continue.. "
  189. echo  - verification of DOTA files will be done automatically on second run..
  190. set launchoptions= -console -forceservice -tcp +app_set_update_flag 570 1 +app_mark_validation 570 1 +app_start_validation 570 1
  191. start "w" "%STEAMPATH%\Steam.exe" %launchoptions% -applaunch 570
  192. timeout /t 20 >nul
  193. echo  - adding Steam shortcut with launch options on Desktop..
  194. set "sopts=-console -silent -forceservice -nocrashmonitor -single_core -tcp" &rem -udpforce  
  195. call cscript /nologo /e:JScript "%~f0" lnk "%STEAMPATH%\Steam.exe" "%sopts%" "%USERPROFILE%\Desktop\Steam.lnk"
  196.  
  197. :: done!
  198. call :mcolor b0 " DONE " 0b " Some changes will take effect after the next PC restart "
  199. pause >nul
  200. exit/b
  201.  
  202. ::----------------------------------------------------------------------------------------------------------------------------------
  203. :: Core functions
  204. ::----------------------------------------------------------------------------------------------------------------------------------
  205. :set_macros outputs %[BS]%=BackSpace %[CR]%=CarriageReturn %[GL]%=Glue/NonBreakingSpace %[DEL]%=DelChar %[DEL7]%=DelCharX7
  206. for /f %%# in ('"prompt $H &for %%h in (1) do rem"') do set "[BS]=%%#" & for /f %%# in ('copy /z "%~dpf0" nul') do set "[CR]=%%#"
  207. pushd "%TEMP%" & echo=WSH.Echo(String.fromCharCode(160))>` & for /f %%# in ('cscript //E:JScript //nologo `') do set "[GL]=%%#"
  208. set/p "=-"<nul>` & set "ECHOP=<nul set/p =%[BS]%" & set "[DEL]=%[BS]%%[GL]%%[BS]%" & call set "[DEL3]=%%[DEL]%%%%[DEL]%%%%[DEL]%%"
  209. set "[\]=-%[DEL]%\..\%[DEL3]%" & set "[/]=-%[DEL]%/..\%[DEL3]%" & set "[DEL6]=%[DEL3]%%[DEL3]%" &set "LABEL=echo. &call :color 70. "
  210. set "INFO=call :color b0 " INFO " &echo" & set "WARN=call :color e0 " WARN " &echo" & set "ERROR=call :color cf " ERROR " &echo"
  211. exit/b                                                                         ||:i AveYo - Used internally by :clearline and :color
  212.  
  213. :clearline %1:Number[how many lines above to delete - macro does not work as intended under Windows 7]
  214. ( if not defined [DEL] call :set_macros ) & setlocal enableDelayedExpansion & set "[LINE]=%[CR]%" & set "[COLS]="
  215. for /f "skip=4 tokens=2 delims=:" %%a in ('mode con') do for %%c in (%%a) do if not defined [COLS] call set "[COLS]=%%c"
  216. ( for /l %%i in (1,1,%[COLS]%) do set "[LINE]=%[DEL]%![LINE]!" ) & ( for /l %%i in (1,1,%~1) do <nul set/p "=![LINE]!" )
  217. endlocal & exit/b                                                                                      ||:i Usage: call :clearline 2
  218.  
  219. :color %1:BgFg.[one or both of hexpair can be _ as defcolor, optional . use newline] %2:text["text with spaces"]
  220. setlocal enableDelayedExpansion &set "bf=%~1" &set "tx=%~2" &set "tx=-%[BS]%!tx:\=%[\]%!" &set "tx=!tx:/=%[/]%!" &set "tx=!tx:"=\"!"
  221. 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%!"
  222. pushd "%TEMP%" & findstr /p /r /a:!bc!!fc! "^^-" "!tx!\..\`" nul & <nul set/p "=%[DEL]%%[DEL6]%" & popd & if defined nl echo/%[GL]%
  223. endlocal & exit/b                        ||:i AveYo - Usage: call :color fc Hello & call :color _c " fancy " & call :color cf. World
  224.  
  225. :mcolor %1:BgFg. %2:"only-quoted-text1" %3:BgFg. %4:"only-quoted-text2" etc.    
  226. setlocal & set "mc=" & for %%C in (%*) do if "%%C"=="%%~C" ( call set "mc=%%mc%% & call :color %%C" ) else call set "mc=%%mc%% %%C"
  227. echo. %mc% & endlocal & exit/b                                  ||:i AveYo - Usage: call :mcolor fc "Hello" _c " fancy " cf. "World"
  228.  
  229. :reg_query %1:KeyName %2:ValueName %3:OutputVariable %4:other_options[example: "/t REG_DWORD"]
  230. setlocal & for /f "skip=2 delims=" %%s in ('reg query "%~1" /v "%~2" /z 2^>nul') do set "rq=%%s" & call set "rv=%%rq:*)    =%%"
  231. endlocal & call set "%~3=%rv%" & exit/b                          ||:i AveYo - Usage:" call :reg_query "HKCU\MyKey" "MyValue" MyVar "
  232.  
  233. ::----------------------------------------------------------------------------------------------------------------------------------
  234. :: Utility functions
  235. ::----------------------------------------------------------------------------------------------------------------------------------
  236. :set_steam outputs %STEAMPATH% %STEAMDATA% %STEAMID%                              
  237. set "STEAMPATH=D:\Steam"                                                            ||:i AveYo:" Override detection here if needed "
  238. if not exist "%STEAMPATH%\Steam.exe" call :reg_query "HKCU\SOFTWARE\Valve\Steam" "SteamPath" STEAMPATH
  239. set "STEAMDATA=" & if defined STEAMPATH for %%# in ("%STEAMPATH:/=\%") do set "STEAMPATH=%%~dpnx#"    ||:i  / pathsep on Windows lul
  240. if not exist "%STEAMPATH%\Steam.exe" echo Cannot find SteamPath in registry & exit/b
  241. call :reg_query "HKCU\SOFTWARE\Valve\Steam\ActiveProcess" "ActiveUser" ACTIVEUSER & set/a "STEAMID=ACTIVEUSER" >nul 2>nul
  242. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  243. if not defined STEAMDATA for /f "delims=" %%# in ('dir "%STEAMPATH%\userdata" /b/o:d/t:w/s 2^>nul') do set "ACTIVEUSER=%%~dp#"
  244. if not defined STEAMDATA for /f "delims=\" %%# in ("%ACTIVEUSER:*\userdata\=%") do set "STEAMID=%%#"
  245. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  246. exit/b
  247.  
  248. :set_dota outputs %STEAMAPPS% %DOTA% %CONTENT%
  249. set "DOTA=D:\Games\steamapps\common\dota 2 beta\game"                               ||:i AveYo:" Override detection here if needed "
  250. if exist "%DOTA%\dota\maps\dota.vpk" set "STEAMAPPS=%DOTA:\common\dota 2 beta=%" & exit/b
  251. set "libfilter=LibraryFolders { TimeNextStatsReport ContentStatsID }"
  252. if not exist "%STEAMPATH%\SteamApps\libraryfolders.vdf" echo Cannot find "%STEAMPATH%\SteamApps\libraryfolders.vdf" & exit/b
  253. for /f usebackq^ delims^=^"^ tokens^=4 %%s in (`findstr /v "%libfilter%" "%STEAMPATH%\SteamApps\libraryfolders.vdf"`) do (
  254.  if exist "%%s\steamapps\appmanifest_570.acf" if exist "%%s\steamapps\common\dota 2 beta\game\dota\maps\dota.vpk" set "libfs=%%s" )
  255. set "STEAMAPPS=%STEAMPATH%\steamapps" & if defined libfs set "STEAMAPPS=%libfs:\\=\%\steamapps"
  256. if not exist "%STEAMAPPS%\common\dota 2 beta\game\dota\maps\dota.vpk" echo Cannot find "%STEAMAPPS%\common\dota 2 beta\game" &exit/b
  257. set "DOTA=%STEAMAPPS%\common\dota 2 beta\game" & set "CONTENT=%STEAMAPPS%\common\dota 2 beta\content"
  258. exit/b
  259.  
  260. :TakeKeyOwnership %1:regpath[ex: "HKCU\Console"] %2:_recurse[optional, default:"-n", "-y"] %3:_sid[optional, default:"S-1-5-32-545"]
  261. rem $src=https://stackoverflow.com/questions/12044432/how-do-i-take-ownership-of-a-registry-key-via-powershell snippet-ized by AveYo
  262. if "%1_"=="_" echo  ERROR! no regpath parameter & exit/b
  263. set "s10=function TakeKeyOwnership { param($regp, $all, $owner); $recurse=($all -eq '-y'); $RP=($regp -split '\\',2); $key=$RP[1];"
  264. set "s11= switch -regex ($RP[0]) { 'HKLM|HKEY_LOCAL_MACHINE' {$HK='LocalMachine'};'HKCC|HKEY_CURRENT_CONFIG' {$HK='CurrentConfig'};"
  265. set "s12=  'HKCR|HKEY_CLASSES_ROOT' {$HK='ClassesRoot'};'HKU|HKEY_USERS' {$HK='Users'};'HKCU|HKEY_CURRENT_USER' {$HK='CurrentUser'}"
  266. set "s13= }; $rootKey=$HK; if ($owner -eq '') {$owner='S-1-5-32-545'}; [System.Security.Principal.SecurityIdentifier]$sid=$owner;"
  267. set "s14= $import='[DllImport("ntdll.dll")] public static extern int RtlAdjustPrivilege(ulong a, bool b, bool c, ref bool d);';"
  268. set "s15= $ntdll=Add-Type -Member $import -Name NtDll -PassThru; $privileges=@{ SeTakeOwnership=9; SeBackup=17; SeRestore=18 };"
  269. set "s16= foreach ($i in $privileges.Values) { $null=$ntdll::RtlAdjustPrivilege($i, 1, 0, [ref]0) };"
  270. set "s17= function Take-KeyPermissions { param($rootKey, $key, $sid, $recurse, $recurseLevel=0);"
  271. set "s18=  $regKey=[Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership');"
  272. set "s19=  $acl=New-Object System.Security.AccessControl.RegistrySecurity; $acl.SetOwner($sid); $regKey.SetAccessControl($acl);"
  273. set "s20=  $acl.SetAccessRuleProtection($false, $false); $regKey.SetAccessControl($acl);"
  274. set "s21=  if ($recurseLevel -eq 0) { $regKey=$regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions');"
  275. set "s22=  $rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,'FullControl','ContainerInherit','None','Allow');"
  276. set "s23=  $acl.ResetAccessRule($rule); $regKey.SetAccessControl($acl) };"
  277. set "s24=  if ($recurse) { foreach($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {"
  278. set "s25=    Take-KeyPermissions $rootKey ($key+'\'+$subKey) $sid $recurse ($recurseLevel+1) } };"
  279. set "s26= }; $ErrorActionPreference='Continue'; Take-KeyPermissions $rootKey $key $sid $recurse }"
  280. for /l %%# in (10,1,26) do call set "ps_TakeKeyOwnership=%%ps_TakeKeyOwnership%%%%s%%#:"=\"%%"
  281. powershell.exe -c "%ps_TakeKeyOwnership%; try { TakeKeyOwnership '%~1' '%~2' '%~3' } catch {}"
  282. exit/b
  283.  
  284. ::----------------------------------------------------------------------------------------------------------------------------------
  285. :"init" Batch entry function                                         ||:i " Batch hybrid engine jumps here after goto='init' trick "
  286. ::----------------------------------------------------------------------------------------------------------------------------------
  287. @echo off & setlocal disabledelayedexpansion &title AveYo's %~nx0 &color 07 &cls & if "%1"=="_SELF_ADMIN" shift &shift & goto :start
  288. reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto :start || call :about 0c & echo  Requesting admin rights..
  289. call cscript /nologo /e:JScript "%~f0" get_rights "%1" & exit
  290.  
  291. ::----------------------------------------------------------------------------------------------------------------------------------
  292. */ // [ JScript functions ] all batch lines above are treated as a /* js comment */ in cscript
  293. function get_rights(fn) {WSH.CreateObject("Shell.Application").ShellExecute(fn,"_SELF_ADMIN "+fn+" "+WSH.Arguments(1),"","runas",1)}
  294. function lnk(exe,param,target) { var lnk=WScript.CreateObject("WScript.Shell").CreateShortcut(target), param=param || '';
  295.   lnk.TargetPath=exe; lnk.Arguments=param; lnk.IconLocation=exe + ",0"; lnk.Save(); }
  296. if (WSH.Arguments.length>=1 && WSH.Arguments(0)=="get_rights") get_rights(WSH.ScriptFullName);
  297. if (WSH.Arguments.length>=1 && WSH.Arguments(0)=="lnk") lnk(WSH.Arguments(1),WSH.Arguments(2),WSH.Arguments(3));
  298. //
RAW Paste Data
Top