Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @(echo off% <#%) &title ToggleGamebar - properly
- set "0=%~f0"&set 1=%*&powershell -nop -win 1 -c iex ([io.file]::ReadAllText($env:0)) &exit/b ||#>)[1]
- ## wrap script
- sp 'HKCU:\Volatile Environment' 'ToggleGamebar' @'
- ## status for GamebarPresenceWriter
- $acikey='Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter'
- if ((gp "HKLM:\SOFTWARE\$acikey" ActivationType -ea 0).ActivationType -eq 0) {$TOGGLE=7;$STATUS='OFF'}else{$TOGGLE=6;$STATUS='ON'}
- ## toggle dialog prompt with Yes, No, Cancel (6,7,2)
- if ($env:1 -ne 6 -and $env:1 -ne 7) {
- $choice=(new-object -ComObject Wscript.Shell).Popup('Disable GamebarPresenceWriter?',0,'GamebarPresenceWriter is '+$STATUS,51)
- if ($choice -eq 2) {break} else {$c=[int]$choice; $env:1=$c}
- }
- ## toggle Gamebar
- sp 'HKCU:\Software\Microsoft\Windows\CurrentVersion\GameDVR' AppCaptureEnabled ($env:1-6) -Type Dword -Force -ea 0
- ## relaunch as Admin passing cmdline args
- $script='-nop -c & {$env:1='+$env:1+';iex((gp Registry::HKEY_Users\S-1-5-21*\Volatile* ToggleGamebar -ea 0)[0].ToggleGamebar)}'
- $null=fltmc;if($LASTEXITCODE -gt 0){start powershell -args $script -verb runas -win 1; break}
- ## reg_own snippet
- function reg_own([string[]]$A){ #key [opt],all,usr,own,acc,perm : reg_own "HKCU:\My","","S-1-5-32-545","","Allow","FullControl"
- $D1=[uri].module.gettype('System.Diagnostics.Process')."GetM`ethods"(42) |where {$_.Name -eq 'SetPrivilege'} #`:no-ev-warn
- 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|foreach {$D1.Invoke($null, @("$_",2))}
- $path=$A[0]; $rk=$path-split':\\',2; $HK=gi -lit Registry::$($rk[0]) -fo; $s=$A[1]; $sps=[Security.Principal.SecurityIdentifier]
- $u=($A[2],'S-1-5-32-544')[!$A[2]];$o=($A[3],$u)[!$A[3]];$w=$u,$o |% {new-object $sps($_)}; $old=!$A[3];$own=!$old; $y=$s-eq'all'
- $rar=new-object Security.AccessControl.RegistryAccessRule( $w[0], ($A[5],'FullControl')[!$A[5]], 1, 0, ($A[4],'Allow')[!$A[4]] )
- $x=$s-eq'none';function Own1($k){$t=$HK.OpenSubKey($k,2,'TakeOwnership');if($t){0,4|%{try{$o=$t.GetAccessControl($_)}catch{$old=0}
- };if($old){$own=1;$w[1]=$o.GetOwner($sps)};$o.SetOwner($w[0]);$t.SetAccessControl($o); $c=$HK.OpenSubKey($k,2,'ChangePermissions')
- $p=$c.GetAccessControl(2);if($y){$p.SetAccessRuleProtection(1,1)};$p.ResetAccessRule($rar);if($x){$p.RemoveAccessRuleAll($rar)}
- $c.SetAccessControl($p);if($own){$o.SetOwner($w[1]);$t.SetAccessControl($o)};if($s){$subkeys=$HK.OpenSubKey($k).GetSubKeyNames()
- foreach($n in $subkeys){Own1 "$k\$n"}}}}; Own1 $rk[1]; if($env:VO){get-acl Registry::$path|fl}} # lean & mean ps snippet by AveYo
- ## use reg_own snippet to unprotect GamebarPresenceWriter registry keys - needed in older windows 10 versions
- reg_own "HKLM:\SOFTWARE\$acikey",'preserve','S-1-1-0'
- reg_own "HKLM:\SOFTWARE\WOW6432Node\$acikey",'preserve','S-1-1-0'
- ## toggle GamebarPresenceWriter activation
- sp "HKLM:\SOFTWARE\$acikey" ActivationType ($env:1-6) -Type Dword -Force -ea 0
- sp "HKLM:\SOFTWARE\WOW6432Node\$acikey" ActivationType ($env:1-6) -Type Dword -Force -ea 0
- ## stop processes
- kill -Force -Name GameBar -ea 0
- kill -Force -Name GamebarPresenceWriter -ea 0
- ## execute script
- '@ -Force -ea 0; iex((gp Registry::HKEY_Users\S-1-5-21*\Volatile* ToggleGamebar -ea 0)[0].ToggleGamebar)
- #-_-# hybrid script, can be pasted directly into powershell console
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement