Advertisement
aveyo

ToggleGameBar-properly

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