Last active
May 8, 2024 17:12
-
-
Save Moojuiceman/b1b0d2d73bbe3b656abb9e5e286ebb8d to your computer and use it in GitHub Desktop.
Powershell script to toggle Astro C40 controller between reading as Xbox/PS4 on windows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Script to toggle Astro C40 controller between reading as Xbox/PS4 on windows. See this page for details: | |
#https://www.reddit.com/r/AstroGaming/comments/e5c5uk/psa_how_to_switch_c40_to_ps4_mode_on_windows_10/ | |
#Self elevate script | |
#http://www.expta.com/2017/03/how-to-self-elevate-powershell-script.html | |
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) | |
{ | |
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) | |
{ | |
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments | |
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine | |
exit | |
} | |
} | |
$keypaths = ('HKLM:\SYSTEM\CurrentControlSet\Enum\USB\VID_9886&PID_0025\','HKLM:\SYSTEM\CurrentControlSet\Enum\USB\VID_9886&PID_0024\') | |
foreach ($keypath in $keypaths) { | |
#Get the registry key | |
try { | |
$key = (gci $keypath)[0] | |
} | |
catch {echo "Error: Key $keypath doesn't exist"; pause; exit} | |
#Check the subkey exists | |
$i1 = $key.Property.IndexOf("LowerFilters") | |
$i2 = $key.Property.IndexOf("LowerFilters_disabled") | |
if ($i1 -eq -1 -and $i2 -ne -1) { | |
#Subkey was disabled, enable it | |
try { | |
Rename-ItemProperty -Path $key.PSPath -Name LowerFilters_disabled -NewName LowerFilters -ErrorAction Stop | |
} | |
catch { | |
$message = $_.Exception.Message | |
echo "Error renaming key: $message"; pause; exit | |
} | |
echo "LowerFilters enabled (Xbox mode)" | |
} | |
elseif ($i1 -ne -1 -and $i2 -eq -1) { | |
#Subkey was enabled, disable it | |
try { | |
Rename-ItemProperty -Path $key.PSPath -Name LowerFilters -NewName LowerFilters_disabled -ErrorAction Stop | |
} | |
catch { | |
$message = $_.Exception.Message | |
echo "Error renaming key: $message"; pause; exit | |
} | |
echo "LowerFilters disabled (PS4 mode)" | |
} | |
else {echo "Error: Couldn't find subkey LowerFilters or LowerFilters_disabled"; pause; exit} | |
} | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautiful work my guy <3 Thanks