Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @goto=init %~nx0
- :: Batch designed for Windows 10 - compatible with Windows 7
- ::----------------------------------------------------------------------------------------------------------------------------------
- :about %1:[0c = red-on-black: Batch was run as user, 0b = cyan-on-black Batch was run as admin]
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :clearline 1
- call :color %1. " --------------------------------------------------------------------- "
- call :color %1. " : WINDOWS_GAMING_STEAM_DOTA_FIX V9.5 : "
- call :color %1. " :---------------------------------------------------------------------: "
- call :color %1. " : -GameDVR -Xbox -GameBarPresenceWriter -FullscreenOpt AppCompatFlags : "
- call :color %1. " : BCD + Network reset SteamService /repair Steam + DOTA cfg refresh : "
- call :color %1. " : Undo script: https://pastebin.com/c4efe7gb : "
- call :color %1. " : : "
- call :color %1. " : Press Alt+F4 to cancel Always run latest version : "
- call :color %1. " --------------------------------------------------------------------- "
- call :color %1. " "
- exit/b
- ::----------------------------------------------------------------------------------------------------------------------------------
- :main [ Batch main function ]
- ::----------------------------------------------------------------------------------------------------------------------------------
- title AveYo's WINDOWS GAMING + STEAM + DOTA FIX
- color 07
- call :about 0b
- ::timeout /t 10
- set "steam_dota=SteamService,Steam_refresh,Dota_cfg"
- set "all_choices=AMD_Nvidia_DVR,GameDVR,GameBar,Xbox,Fullscreen_optimizations,AppCompatFlags,BCD_reset,Network_reset,%steam_dota%"
- set "def_choices=AMD_Nvidia_DVR,GameDVR,GameBar,Fullscreen_optimizations,AppCompatFlags,BCD_reset,Network_reset,%steam_dota%"
- call :choices MOD_CHOICES "%all_choices%" "%def_choices%" "Fix" 14 MidnightBlue Snow
- for %%o in (%all_choices%) do set "%%o=" &rem undefine all initial choices
- for %%o in (%MOD_CHOICES%) do set "%%o=1" &rem then redefine selected ones to 1
- :: export choices to registry
- if defined MOD_CHOICES reg add "HKCU\Environment" /v "Fix choices" /t REG_SZ /d "%MOD_CHOICES%" /f >nul 2>nul
- set "CHOICES=%MOD_CHOICES%"
- set "ten=1" & ver | find "10." > nul
- if errorlevel 1 set "ten="
- if not defined AMD_Nvidia_DVR goto skip_AMD_Nvidia_DVR
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " AMD DVR / Nvidia GFE / ShadowPlay " 07. " to prevent crashes, stutters and fps loss.. "
- :: amd dvr options and hotkeys
- set "regkey=SOFTWARE\AMD\DVR"
- set "options=CustomOverlayEnabled DesktopRecordingEnabled DvrEnabled InstantReplayEnabled RecordPerfUI RigInfoOverlayEnabled"
- set "hotkey1=SaveInstantReplayHotkey TakeScreenshotHotkey ToggleCameraHotkey ToggleDvrRecordingHotkey ToggleDvrToolbarHotkey"
- set "hotkey2=ToggleMicrophoneHotkey ToggleRsHotkey ToggleRsPerfRecordingHotkey ToggleRsPerfUiHotkey ToggleStreamingHotkey"
- for %%a in (HKCU HKLM) do for %%B in (32 64) do (
- for %%. in (%options%) do reg add "%%a\%regkey%" /v "%%." /t REG_DWORD /d 0 /f /reg:%%B
- for %%. in (%hotkey1% %hotkey2%) do reg add "%%a\%regkey%" /v "%%." /d "none" /f /reg:%%B
- ) >nul 2>nul
- :: amd dvr task disable and block
- schtasks /Change /TN "StartDVR" /DISABLE >nul 2>nul
- set "tasks=%SystemRoot%\System32\Tasks"
- if exist "%tasks%\StartDVR" (
- pushd "%tasks%"
- copy /y StartDVR StartDVR.bak
- del /f /q StartDVR
- mkdir StartDVR
- icacls StartDVR /deny "Everyone:(OI)(CI)W"
- popd
- ) >nul 2>nul
- :: amd dvr startup entry
- set "amddvr=C:\Program Files\AMD\CNext\CNext\amddvr.exe"
- for %%a in (HKCU HKLM) do reg delete "%%a\Software\Microsoft\Windows\CurrentVersion\Run" /v "%amddvr%" /f >nul 2>nul
- :: amd dvr / relive / telemetry executable block (amd force relive to run even if not selected as an install option)
- call :BlockExecution "amddvr amdow"
- :: amd disable overclock
- taskkill /im RadeonSettings.exe >nul 2>nul
- reg delete HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000 /v PP_CNEscapeInput /f >nul 2>nul
- ::schtasks /Change /TN "StartCN" /DISABLE >nul 2>nul
- set "regkey=HKCU\SOFTWARE\AMD\CN"
- reg add "%regkey%" /v "EulaAccepted" /d "False" /f >nul 2>nul
- reg add "%regkey%" /v "OverclockEnabled" /t REG_DWORD /d 0 /f >nul 2>nul
- ::reg add "%regkey%\Performance" /v "RecordInterval" /t REG_DWORD /d 120 /f >nul 2>nul
- reg add "%regkey%\ANALYTICS" /v "AnalyticsUploadDays" /d "3652" /f >nul 2>nul
- set "regkey=HKCU\Software\ATI\ACE\Settings\Runtime"
- reg add "%regkey%\Platform\AMDOverDrive" /v "EULA_Accepted" /d "False" /f >nul 2>nul
- reg add "%regkey%\Graphics\OverDrive5" /v "OverclockEnabled_DEF" /d "False" /f >nul 2>nul
- :: nvidia gfe / shadowplay / telemetry executable block (nvidia restores disabled services to force their crap to run)
- call :BlockExecution "nvstreamer NvTelemetryContainer NvContainer" &rem nvnodejslauncher NVNetworkService
- :skip_AMD_Nvidia_DVR
- if not defined GameDVR goto skip_GameDVR
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " Windows Game DVR " 07. " to prevent stutters and fps loss.. "
- (
- reg add "HKCU\Software\Microsoft\GameBar" /v "AllowAutoGameMode" /t REG_DWORD /d "0" /f
- reg add "HKCU\Software\Microsoft\GameBar" /v "ShowStartupPanel" /t REG_DWORD /d "0" /f
- reg add "HKCU\Software\Microsoft\GameBar" /v "UseNexusForGameBarEnabled" /t REG_DWORD /d "0" /f
- reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AppCaptureEnabled" /t REG_DWORD /d "0" /f
- reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "AudioCaptureEnabled" /t REG_DWORD /d "0" /f
- reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR" /v "CursorCaptureEnabled" /t REG_DWORD /d "0" /f
- reg add "HKCU\System\GameConfigStore" /v "GameDVR_Enabled" /t REG_DWORD /d "0" /f
- reg add "HKLM\Software\Policies\Microsoft\Windows\GameDVR" /v "AllowgameDVR" /t REG_DWORD /d "0" /f
- ) >nul 2>nul
- call :BlockExecution "bcastdvr GamePanel"
- :skip_GameDVR
- if not defined Xbox goto skip_Xbox
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " Xbox " 07. " to prevent stutters and fps loss.. "
- (
- reg add "HKLM\System\CurrentControlSet\Services\xbgm" /v "Start" /t REG_DWORD /d "4" /f
- schtasks /Change /TN "Microsoft\XblGameSave\XblGameSaveTask" /DISABLE
- schtasks /Change /TN "Microsoft\XblGameSave\XblGameSaveTaskLogon" /DISABLE
- sc config XblAuthManager start= disabled
- sc config XblGameSave start= disabled
- sc config XboxGipSvc start= disabled
- sc config XboxNetApiSvc start= disabled
- ) >nul 2>nul
- :skip_Xbox
- if not defined GameBar goto skip_GameBar
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " GameBarPresenceWriter " 07. " to prevent micro-stutters.. "
- rem call :BlockExecution "GameBarPresenceWriter"
- set "regkey=Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter"
- call :reg_takeownership "HKLM\SOFTWARE\%regkey%" Administrators recursive
- call :reg_takeownership "HKLM\SOFTWARE\WOW6432Node\%regkey%" Administrators recursive
- reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f /reg:64 >nul 2>nul
- reg add "HKLM\SOFTWARE\%regkey%" /v "ActivationType" /t REG_DWORD /d 0 /f /reg:32 >nul 2>nul
- :skip_GameBar
- if not defined Fullscreen_optimizations goto skip_Fullscreen_optimizations
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " Fullscreen so-called optimizations " 07. " to prevent stutters and fps loss .. "
- set "COMPATFLAGS=~ DISABLEDXMAXIMIZEDWINDOWEDMODE"
- :: Query programs with AppCompatFlags already set and override them
- set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" &set "foropts="usebackq delims=""
- for %%a in (HKCU HKLM) do for %%B in (32 64) do (
- for /f %foropts% %%s in (`reg query "%%a\%regkey%" /reg:%%B 2^>nul ^| find "\" ^| find /i ".exe"`) do call :Filter %%a %%B "%%s" P
- )
- :: Get current user sid with vmic
- for /f "usebackq delims= " %%s in (`wmic useraccount where "name='%username%'" get sid ^| find "S-"`) do set "sid=%%s"
- :: Query bam service ( .i. microsoft... ) for previously executed programs, filter out built-in ones and add AppCompatFlags
- set "regkey=HKLM\SYSTEM\CurrentControlSet\Services\bam\UserSettings\%sid%"
- 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 (
- call :Filter %%a %%B "%%s" N
- )
- :skip_Fullscreen_optimizations
- if not defined AppCompatFlags goto skip_AppCompatFlags
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Disabling " 70 " AppCompatFlags " 07. " to reduce annoyances and prevent crashes.. "
- set "regkey=Software\Policies\Microsoft\Windows\AppCompat"
- for %%a in (HKCU HKLM) do (
- reg add "%%a\%regkey%" /v "DisablePCA" /t REG_DWORD /d 1 /f
- reg add "%%a\%regkey%" /v "DisableUAR" /t REG_DWORD /d 1 /f
- reg add "%%a\%regkey%" /v "AITEnable" /t REG_DWORD /d 0 /f
- ) >nul 2>nul
- :: set conservative tdr limits
- set "regkey=HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers"
- (
- reg add "%regkey%" /v TdrLevel /t REG_DWORD /d 0x3 /f
- reg add "%regkey%" /v TdrDelay /t REG_DWORD /d 0xa /f
- reg add "%regkey%" /v TdrDdiDelay /t REG_DWORD /d 0xa /f
- reg add "%regkey%" /v TdrLimitCount /t REG_DWORD /d 0xa /f
- reg add "%regkey%" /v TdrLimitTime /t REG_DWORD /d 0x12c /f
- ) >nul 2>nul
- :: clear event logs for applications
- wevtutil.exe cl "Application" >nul 2>nul
- :skip_AppCompatFlags
- if not defined BCD_reset goto skip_BCD_reset
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Resetting " 70 " BCD " 07. " to prevent crashes and VAC false-positives.. "
- for %%s in ("" " {default}" " {current}") do (
- bcdedit /deletevalue%%~s nointegritychecks
- bcdedit /deletevalue%%~s loadoptions
- bcdedit /debug%%~s off
- bcdedit /deletevalue%%~s nx
- bcdedit /set%%~s bootstatuspolicy ignoreallfailures
- ) >nul 2>nul
- :skip_BCD_reset
- if not defined Network_reset goto skip_Network_reset
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Resetting " 70 " Network " 07. " to prevent conectivity issues.. "
- rem netsh advfirewall reset
- (
- ipconfig /flushdns
- nbtstat -R
- nbtstat -RR
- netsh int ipv4 reset
- netsh int ipv6 reset
- netsh winsock reset
- ) >nul 2>nul
- :skip_Network_reset
- :: Generic windows gaming fixes end here, Steam and Dota fixes below
- if not defined SteamService if not defined Steam_refresh if not defined Dota_cfg goto done
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 0e " You can press " e0 " ALT+F4 " 0e. " now if you don't need to reset STEAM and DOTA cfg .. "
- timeout /t 10
- call :clearline 3
- call :set_steam
- call :set_dota
- echo.
- echo STEAM = %STEAMDATA%
- echo DOTA2 = %DOTA%
- taskkill /t /f /im steam.exe >nul 2>nul
- :: disabling steam start with windows
- reg add "HKCU\Software\Valve\Steam" /v "AlreadyRetriedOfflineMode" /t REG_DWORD /d 1 /f >nul 2>nul
- reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "Steam" /f >nul 2>nul
- :: disabling steam and dota fullscreen so-called optimization and set dpi scaling to application..
- set "COMPATFLAGS=~ DISABLEDXMAXIMIZEDWINDOWEDMODE HIGHDPIAWARE"
- set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
- for %%. in ("%STEAMPATH%\Steam.exe" "%DOTA%\bin\win64\dota2.exe" "%DOTA%\bin\win32\dota2.exe") do (
- for %%a in (HKCU HKLM) do for %%B in (32 64) do reg delete "%%a\%regkey%" /v "%%~." /f /reg:%%B
- rem for %%B in (32 64) do reg add "HKCU\%regkey%" /v "%%~." /t REG_SZ /d "%COMPATFLAGS%" /f /reg:%%B
- ) >nul 2>nul
- :: reseting steam and dota image file execution + disabling sehop (can add for all programs by uncommenting :AppCompatFlags section)
- set "exes=Steam.exe steamwebhelper.exe GameOverlayUI.exe dota2.exe"
- set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
- for %%a in (%exes%) do for %%B in (32 64) do (
- reg delete "%regkey%\%%a" /va /f /reg:%%B
- reg add "%regkey%\%%a" /v "DisableExceptionChainValidation" /t REG_DWORD /d 1 /f /reg:%%B
- ) >nul 2>nul
- :: removing firewall rules
- for %%. in ("dota2" "Dota 2" "Steam" "Steam Web Helper") do netsh advfirewall firewall delete rule name=%%. >nul 2>nul
- if not defined SteamService goto skip_SteamService
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor 07 " Repairing " 70 " SteamService " 07. " to prevent crashes.. "
- set "sservice=%CommonProgramFiles(x86)%\Steam\SteamService.exe" &set "sservice32=%CommonProgramFiles%\Steam\SteamService.exe"
- if exist "%STEAMPATH%\bin\SteamService.exe" start "w" /MIN /WAIT "%STEAMPATH%\bin\SteamService.exe" /repair &goto skip_SteamService
- if exist "%sservice%" start "w" /MIN /WAIT "%sservice%" /repair &goto skip_SteamService
- if exist "%sservice32% "start "w" /MIN /WAIT "%sservice32%" /repair
- :skip_SteamService
- if not defined Steam_refresh goto skip_Steam_refresh
- ::----------------------------------------------------------------------------------------------------------------------------------
- if not exist "%STEAMPATH%\steamapps\*.*" goto skip_Steam_refresh
- call :mcolor 07 " Resetting " 70 " Steam configuration " 07. " SteamApps Library is left untouched.. "
- cd/d "%STEAMPATH%"
- for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v "steam.exe"`) do del /f/q "%%a" >nul 2>nul
- 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
- set ".=%USERPROFILE%\AppData\Local\Steam"
- del /f/s/q "%.%" >nul 2>nul &rmdir /s/q "%.%" >nul 2>nul
- :skip_Steam_refresh
- if not defined Dota_cfg goto skip_Dota_cfg
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :set_steam & call :set_dota
- if not exist "%DOTA%\bin\win32\*.*" goto skip_Dota_cfg
- call :mcolor 07 " Resetting " 70 " DOTA configuration " 07. " Hotkeys + Settings are restored from Cloud.. "
- cd/d "%DOTA%\core"
- for %%a in (cfg scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
- cd/d "%DOTA%\dota"
- for %%a in (core scripts) do del /f/s/q %%a >nul 2>nul &rmdir /s/q %%a >nul 2>nul
- for /f "usebackq tokens=*" %%a in (`dir /a:-D /b ^| findstr /l /i /v ".vpk"`) do del /f/q "%%a" >nul 2>nul
- del /f/q cfg\vide*.txt >nul 2>nul
- del /f/q cfg\*.vcfg >nul 2>nul
- set "vcfg=%DOTA%\dota\cfg\user_keys_default.vcfg"
- powershell -noprofile -c "[IO.File]::WriteAllText('%vcfg%',([IO.File]::ReadAllText('%~f0') -split ':vcfg\:.*\n')[1])"
- goto vcfg_done
- :vcfg: user_keys_default.vcfg
- "config"
- {
- "bindings"
- {
- "\" "toggleconsole"
- "F10" "return_to_tools_from_engine"
- }
- "analogbindings"
- {
- }
- }
- :vcfg:
- :vcfg_done
- :: prevent launching the game before verification is finished + force exe refresh
- del /f/q "%DOTA%\bin\win64\dota2.exe" >nul 2>nul
- del /f/q "%DOTA%\bin\win32\dota2.exe" >nul 2>nul
- del /f/q "%DOTA%\bin\vidcfg.bin" >nul 2>nul
- echo - removing old crash dump files..
- del /f/q "%DOTA%\bin\win64\*.mdmp" >nul 2>nul
- del /f/q "%DOTA%\bin\win32\*.mdmp" >nul 2>nul
- echo - removing temporary files..
- rem (downloading temp workshop )
- for %%a in (downloading temp) do (
- del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
- rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
- )
- rem (downloading temp workshop )
- for %%a in (downloading temp) do (
- takeown /f "%STEAMAPPS%\%%a" /r /d y >nul 2>nul
- icacls "%STEAMAPPS%\%%a" /reset /t /q >nul 2>nul
- del /f/s/q "%STEAMAPPS%\%%a" >nul 2>nul
- rmdir /s/q "%STEAMAPPS%\%%a" >nul 2>nul
- )
- ::----------------------------------------------------------------------------------------------------------------------------------
- if not exist "%STEAMPATH%\Steam.exe" goto skip_Dota_cfg
- call :mcolor 07 " Reloading " 70 " Steam " 07. " - login to continue.. "
- echo - verification of DOTA files will be done automatically on second run..
- set launchoptions= -console -forceservice -tcp +app_set_update_flag 570 1 +app_mark_validation 570 1 +app_start_validation 570 1
- start "w" "%STEAMPATH%\Steam.exe" %launchoptions% -applaunch 570
- timeout /t 20 >nul
- echo - adding Steam shortcut with launch options on Desktop..
- set "L1=-silent -console -no-browser -nofriendsui -vrdisable -windowed -manuallyclearframes 0 -forceservice"
- set "L2=-nocrashmonitor -nocrashdialog -norepairfiles -noverifyfiles -skipstreamingdrivers +\"@AllowSkipGameUpdate 1 -"
- set "pslnk=$lnk=(New-Object -comObject WScript.Shell).CreateShortcut(\"$env:userprofile\Desktop\Steam_tweak.lnk\");"
- powershell -c "%pslnk%;$lnk.TargetPath=\"${env:ProgramFiles(x86)}\Steam\Steam.exe\";$lnk.Arguments='%L1% %L2%';$lnk.Save();"
- :skip_Dota_cfg
- :done
- ::----------------------------------------------------------------------------------------------------------------------------------
- call :mcolor b0 " DONE " 0b " Some changes will take effect after the next PC restart "
- timeout /t 12 >nul
- exit
- ::----------------------------------------------------------------------------------------------------------------------------------
- :: Utility functions
- ::----------------------------------------------------------------------------------------------------------------------------------
- :BlockExecution %1:[executable names without extension, like "bcastdvr GamePanel" ]
- set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
- for %%a in (%~1) do for %%B in (32 64) do (
- reg add "%regkey%\%%a.exe" /v Debugger /t REG_SZ /d "%windir%\System32\systray.exe" /f /reg:%%B
- ) >nul 2>nul
- exit/b
- :Filter %1:[HKCU or HKLM] %2:[32 or 64] %3:[string from reg query] %4:[P = keep path, N = just name]
- set "rq=%~3"
- set "rq=%rq: =%"
- call set "rv=%%rq:*REG_=%%"
- call set "rv=%%rq:REG_%rv%=%%"
- if "%4"=="P" for %%s in ("%rv%") do call :AppCompatFlags %~1 %~2 "%%~s" %~4
- if "%4"=="N" for %%s in ("%rv%") do (
- if /i "%%~nxs"=="conhost.exe" exit/b
- if /i "%%~nxs"=="cmd.exe" exit/b
- if /i "%%~nxs"=="powershell.exe" exit/b
- if exist "%windir%\system32\%%~nxs" exit/b
- if exist "%windir%\%%~nxs" exit/b
- call :AppCompatFlags %~1 %~2 "%%~nxs" %~4
- )
- exit/b
- :AppCompatFlags %1:[HKCU or HKLM] %2:[32 or 64] %3:[string from :FilterPrograms] %4:[P = keep path, N = just name]
- if "%~1%~2"=="HKCU32" echo %~3 &rem there are several reg add operations, so only spew program name once
- set "regkey=Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
- reg add "%~1\%regkey%" /v "%~3" /t REG_SZ /d "%COMPATFLAGS%" /f /reg:%~2 >nul 2>nul
- :: uncomment lines below to also disable sehop for all programs previously executed
- rem set "regkey=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
- rem if "%4"=="N" reg add "%regkey%\%%~3" /v "DisableExceptionChainValidation" /t REG_DWORD /d 1 /f >nul 2>nul
- exit/b
- :reg_takeownership [USAGE] call :reg_takeownership "HKLM\MyKey" [OPTIONAL] "Administrators" recursive
- if not defined ps_RegTakeOwnership for %%s in (
- "$dll0='[DllImport(''ntdll.dll'')]public static extern int RtlAdjustPrivilege(ulong a,bool b,bool c,ref bool d);';"
- "$nt=Add-Type -Member $dll0 -Name NtDll -PassThru; foreach($i in @(9,17,18)){$null=$nt::RtlAdjustPrivilege($i,1,0,[ref]0)};"
- "function Reg_TakeOwnership { param($hive, $key, $own, $inherit=$false);"
- " $reg=[Microsoft.Win32.Registry]::$hive.OpenSubKey($key,'ReadWriteSubTree','TakeOwnership');"
- " $acl=New-Object System.Security.AccessControl.RegistrySecurity; $acl.SetOwner($own); $reg.SetAccessControl($acl);"
- " $acl.SetAccessRuleProtection($false,$false);$reg.SetAccessControl($acl);"
- " $reg=$reg.OpenSubKey('','ReadWriteSubTree','ChangePermissions'); if($inherit){"
- " $rule=New-Object System.Security.AccessControl.RegistryAccessRule($own,'FullControl','ContainerInherit','None','Allow');"
- " $acl.ResetAccessRule($rule); $reg.SetAccessControl($acl);} }; $rk=$regkey -split '\\\\',2; $key=$rk[1];"
- "switch -regex ($rk[0]) { '[mM]'{$HK='LocalMachine'};'[uU]'{$HK='CurrentUser'}; default {$HK='ClassesRoot'}; }; $HK; $key;"
- "if($user -eq ''){$user='Administrators'}; [System.Security.Principal.NTAccount]$owner=$user; $rcsv=($recursive -ne '');"
- "Reg_TakeOwnership $HK $key $owner $true; if($rcsv){$r=[Microsoft.Win32.Registry]::$HK.OpenSubKey($key);"
- "foreach($sk in $r.GetSubKeyNames()){$sk; try{ Reg_TakeOwnership $HK $($key+'\\'+$sk) $owner }catch{} }} "
- ) do call set "ps_RegTakeOwnership=%%ps_RegTakeOwnership%%%%~s"
- powershell.exe -c " $regkey='%~1';$user='%~2';$recursive='%~3'; %ps_RegTakeOwnership:'=\"%;" &exit/b by AveYo
- :set_steam [OUTPUTS] STEAMPATH STEAMDATA STEAMID AveYo : Override detection below if needed
- set "STEAMPATH=D:\Steam"
- if not exist "%STEAMPATH%\Steam.exe" call :reg_query STEAMPATH "HKCU\SOFTWARE\Valve\Steam" "SteamPath"
- set "STEAMDATA=" & if defined STEAMPATH for %%. in ("%STEAMPATH%") do set "STEAMPATH=%%~dpnx."
- if not exist "%STEAMPATH%\Steam.exe" call :end # Cannot find SteamPath in registry
- call :reg_query ACTIVEUSER "HKCU\SOFTWARE\Valve\Steam\ActiveProcess" "ActiveUser" & set/a "STEAMID=ACTIVEUSER" >nul 2>nul
- if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
- if not defined STEAMDATA for /f "delims=" %%. in ('dir "%STEAMPATH%\userdata" /b/o:d/t:w/s 2^>nul') do set "ACTIVEUSER=%%~dp."
- if not defined STEAMDATA for /f "delims=\" %%. in ("%ACTIVEUSER:*\userdata\=%") do set "STEAMID=%%."
- if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
- exit/b
- :set_dota [OUTPUTS] STEAMAPPS DOTA CONTENT AveYo : Override detection below if needed
- set "DOTA=D:\Games\steamapps\common\dota 2 beta\game"
- if exist "%DOTA%\dota\maps\dota.vpk" set "STEAMAPPS=%DOTA:\common\dota 2 beta=%" & exit/b
- set "libfilter=LibraryFolders { TimeNextStatsReport ContentStatsID }"
- if not exist "%STEAMPATH%\SteamApps\libraryfolders.vdf" call :end # Cannot find "%STEAMPATH%\SteamApps\libraryfolders.vdf"
- for /f usebackq^ delims^=^"^ tokens^=4 %%s in (`findstr /v "%libfilter%" "%STEAMPATH%\SteamApps\libraryfolders.vdf"`) do (
- if exist "%%s\steamapps\appmanifest_570.acf" if exist "%%s\steamapps\common\dota 2 beta\game\dota\pak01_*.vpk" set "libfs=%%s")
- set "STEAMAPPS=%STEAMPATH%\steamapps" & if defined libfs set "STEAMAPPS=%libfs:\\=\%\steamapps"
- if not exist "%STEAMAPPS%\common\dota 2 beta\game\dota\maps\dota.vpk" call :end # Missing "%STEAMAPPS%\common\dota 2 beta\game"
- set "DOTA=%STEAMAPPS%\common\dota 2 beta\game" & set "CONTENT=%STEAMAPPS%\common\dota 2 beta\content"
- exit/b
- :unselect [USAGE] call :unselect choice variable[containing a list of choices separated by , comma]
- if not defined %~2 exit/b
- setlocal & call set "ops=%%%~2%%" & call set "ops=%%ops:,%~1=%%" & call set "ops=%%ops:%~1,=%%" & call set "ops=%%ops:%~1=%%"
- endlocal & call set "%~2=%ops%" & exit/b
- :choices [USAGE] call :choices ResultVar "all,&choices" "default,choices" [OPTIONAL] "title" "textsize" "backcolor" "textcolor"
- (set "params=" & for %%s in (%*) do call set "params=%%params%% '%%~s'") & if not defined ps_? for /f delims^=^ eol^= %%. in (
- "function Choices($ov='', $all, $def, $n='Choices', [byte]$sz=12, $bc='MidnightBlue', $fc='Snow', $saved='HKCU:\Environment'){"
- "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $f=New-Object System.Windows.Forms.Form;"
- "$i=1; $j=1; $a=$all.split(','); $s=$def.split(','); $reg=(Get-ItemProperty $saved).$n; if($reg.length){$s=$reg.split(',') };"
- "function rst(){$cb | foreach{$_.Checked=0; if($s -contains $_.Text){$_.Checked=1 } } }; $f.Add_Shown({rst; $f.Activate()});"
- "$cb=@(); $a | foreach{$c=New-Object System.Windows.Forms.CheckBox;$c.Name=$i;$c.Text=$_;$c.MinimumSize='240,14';$c.AutoSize=1;"
- "$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++};"
- "$bt=@(); @('OK','Reset','Cancel') | foreach{$b=New-Object System.Windows.Forms.Button; $b.Text=$_; $b.AutoSize=1;"
- "$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};"
- "$v=@(); $f.AcceptButton=$bt[0]; $f.CancelButton=$bt[2]; $bt[0].DialogResult=1; $bt[1].add_Click({$s=$def.split(',');rst});"
- "$f.Text=$n; $f.BackColor=$bc; $f.ForeColor=$fc; $f.StartPosition=4; $f.AutoSize=1; $f.AutoSizeMode=0; $f.FormBorderStyle=3;"
- "$f.MaximizeBox=0; $r=$f.ShowDialog(); if($r -eq 1){$cb | foreach{if($_.Checked){$v+=$_.Text}}; $val=$v -join ',';"
- "$null=New-ItemProperty -Path $saved -Name $n -Value $val -Force; return $val } }") do set "/=%%~." &call set "ps_?=%%/:" "=%%"
- (for /f "delims=" %%s in ('powershell -noprofile -c "%ps_?%; Choices %params%;"') do set "%1=%%s") &exit/b snippet by AveYo
- :reg_query [USAGE] call :reg_query ResultVar "HKCU\KeyName" "ValueName"
- (for /f "skip=2 delims=" %%s in ('reg query "%~2" /v "%~3" /z 2^>nul') do set ".=%%s" & call set "%~1=%%.:*) =%%") & exit/b
- ::----------------------------------------------------------------------------------------------------------------------------------
- :: Core functions
- ::----------------------------------------------------------------------------------------------------------------------------------
- :set_macros [OUTPUTS] %[BS]%=BackSpace %[CR]%=CarriageReturn %[GL]%=Glue/NonBreakingSpace %[DEL]%=DelChar %[DEL7]%=DelCharX7
- pushd "%TEMP%" & echo=WSH.Echo(String.fromCharCode(160))>` & for /f %%. in ('cscript //E:JScript //nologo `') do set "[GL]=%%."
- for /f %%. in ('echo prompt $H ^| cmd') do set "[BS]=%%." & for /f %%. in ('copy /z "%~dpf0" nul') do set "[CR]=%%."
- for /f "tokens=2 delims=1234567890" %%. in ('shutdown /?^|findstr /bc:"E"') do set "[TAB]=%%."
- set/p "=-"<nul>` &set "ECHOP=<nul set/p =%[BS]%" &set "[DEL]=%[BS]%%[GL]%%[BS]%" &call set "[DEL3]=%%[DEL]%%%%[DEL]%%%%[DEL]%%"
- set "[L]=-%[DEL]%\..\%[DEL3]%"&set "[J]=-%[DEL]%/..\%[DEL3]%"&set "[DEL6]=%[DEL3]%%[DEL3]%" &set "LABEL=echo. &call :color 70. "
- set "INFO=call :color b0 " INFO " &echo" & set "WARN=call :color e0 " WARN " &echo" & set "ERROR=call :color cf " ERROR " &echo"
- exit/b &REM AveYo - :clearline and :color depend on this, initialize with call :set_macros
- :clearline Number[how many lines above to delete - macro designed for Windows 10 but adjusted to work under 7 too]
- ( if not defined [DEL] call :set_macros ) &setlocal enableDelayedExpansion & set "[LINE]=%[CR]%" & set "[LINE7]=" & set "[COL]="
- 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"
- 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]%%"
- for /L %%a in (1,1,%[C7]%) do call set "[LINE7]=%%[LINE7]%%%[BS]%"
- ver | find "10." >nul & if errorlevel 1 (for /L %%i in (1,1,%1) do echo;%[TAB]%%[LINE7]%%[CLR]% & echo;%[TAB]%%[LINE7]% ) else (
- for /l %%i in (1,1,%1) do <nul set/p "=![LINE]!" )
- endlocal & exit/b &REM Usage: call :clearline 2
- :color BgFg.[one or both of hexpair can be _ as defcolor, optional . use newline] text["text with spaces"]
- setlocal enableDelayedExpansion &set "bf=%~1"&set "tx=%~2"&set "tx=-%[BS]%!tx:\=%[L]%!"&set "tx=!tx:/=%[J]%!"&set "tx=!tx:"=\"!"
- 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%!"
- pushd "%TEMP%" & findstr /p /r /a:!bc!!fc! "^^-" "!tx!\..\`" nul &<nul set/p "=%[DEL]%%[DEL6]%" &popd &if defined nl echo/%[GL]%
- endlocal & exit/b &REM AveYo - Usage: call :color fc Hello & call :color _c " fancy " & call :color cf. World
- :mcolor BgFg. "only-quoted-text1" BgFg. "only-quoted-text2" etc.
- set "-mc~=" & for %%C in (%*) do if "%%C"=="%%~C" (call set "-mc~=%%-mc~%% & call :color %%C") else call set "-mc~=%%-mc~%% %%C"
- echo. %-mc~% & exit/b &REM AveYo - Usage: call :mcolor fc "Hello" _c " fancy " cf. "World"
- :end %1:Message[Delayed termination with status message - prefix with # to signal failure]
- echo. & if "%~1"=="#" ( %ERROR% %* & timeout /t 32 & exit ) else %INFO% %* & timeout /t 20 & exit
- ::------------------------------------------------------------------------------------------------------------------------------
- :init Console preferences sets color table and prevents mouseclicks pausing the script
- ::------------------------------------------------------------------------------------------------------------------------------
- @echo off &setlocal &set "BackClr=0"&set "TextClr=7"&set "Columns=40" &set "Lines=120" &set "Buff=9999" &call :clearline 1 2>nul
- if not "%1"=="init" set/a SColors=0x%BackClr%%TextClr% & set/a WSize=Columns*256*256+Lines & set/a SBSize=Buff*256*256+Lines
- if not "%1"=="init" for %%. in ("HKCU\Console\init" ) do (
- reg add %%. /v QuickEdit /d 0 /t REG_DWORD /f ® add %%. /v CtrlKeyShortcutsDisabled /d 0 /t REG_DWORD /f
- reg add %%. /v LineWrap /d 0 /t REG_DWORD /f ® add %%. /v LineSelection /d 1 /t REG_DWORD /f
- reg add %%. /v FaceName /d "Lucida Console" /t REG_SZ /f ® add %%. /v FontSize /d 0xe0008 /t REG_DWORD /f
- reg add %%. /v ScreenBufferSize /d %SBSize% /t REG_DWORD /f ® add %%. /v WindowSize /d %WSize% /t REG_DWORD /f
- reg add %%. /v ScreenColors /d %SColors% /t REG_DWORD /f ® add HKCU\Console /v ForceV2 /d 1 /t REG_DWORD /f
- reg add %%. /v ColorTable00 /d 0x000000 /t REG_DWORD /f ® add %%. /v ColorTable08 /d 0x808080 /t REG_DWORD /f &REM black dg
- reg add %%. /v ColorTable01 /d 0x800000 /t REG_DWORD /f ® add %%. /v ColorTable09 /d 0xff0000 /t REG_DWORD /f &REM blue lb
- reg add %%. /v ColorTable02 /d 0x008000 /t REG_DWORD /f ® add %%. /v ColorTable10 /d 0x00ff00 /t REG_DWORD /f &REM green lg
- reg add %%. /v ColorTable03 /d 0x808000 /t REG_DWORD /f ® add %%. /v ColorTable11 /d 0xffff00 /t REG_DWORD /f &REM cyan lc
- reg add %%. /v ColorTable04 /d 0x000080 /t REG_DWORD /f ® add %%. /v ColorTable12 /d 0x0000ff /t REG_DWORD /f &REM red lr
- reg add %%. /v ColorTable05 /d 0x800080 /t REG_DWORD /f ® add %%. /v ColorTable13 /d 0xff00ff /t REG_DWORD /f &REM purple lp
- reg add %%. /v ColorTable06 /d 0x008080 /t REG_DWORD /f ® add %%. /v ColorTable14 /d 0x00ffff /t REG_DWORD /f &REM yellow ly
- reg add %%. /v ColorTable07 /d 0xc0c0c0 /t REG_DWORD /f ® add %%. /v ColorTable15 /d 0xffffff /t REG_DWORD /f &REM lgray wh
- ) >nul 2>nul
- rem if not "%1"=="init" ( cd/d %~dp0 & start "init" "%~f0" init & exit/b ) else goto main &rem " Simple no admin self-restart "
- if "%1"=="init" goto main &rem " Admin self-restart flag found, jump to :main "
- reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto main || call :about 0c & echo Requesting admin rights..
- powershell -noprofile -c "Start-Process cmd.exe -ArgumentList '/c \"%~f0\" init' -verb RunAs"
- exit
- ::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement