$ErrorActionPreference = 'Stop' $DllUrl = 'https://steam.sarl/client' function Stop-Install([string]$Message) { Write-Host $Message -ForegroundColor Red exit 1 } $SteamPath = $null foreach ($key in 'HKCU:\Software\Valve\Steam', 'HKLM:\SOFTWARE\Valve\Steam', 'HKLM:\SOFTWARE\WOW6432Node\Valve\Steam') { $path = (Get-ItemProperty $key -ErrorAction SilentlyContinue).InstallPath if ($path -and (Test-Path (Join-Path $path 'Steam.exe'))) { $SteamPath = $path; break } } if (-not $SteamPath) { Stop-Install '没有检测到 Steam。' } $target = Join-Path $SteamPath 'xinput1_4.dll' $download = Join-Path $env:TEMP 'steam-sideload.download' try { Invoke-WebRequest -UseBasicParsing -Uri $DllUrl -OutFile $download -TimeoutSec 180 Start-Process -FilePath (Join-Path $SteamPath 'Steam.exe') -ArgumentList '-shutdown' -ErrorAction SilentlyContinue $deadline = (Get-Date).AddSeconds(15) while ((Get-Date) -lt $deadline -and (Get-Process steam -ErrorAction SilentlyContinue)) { Start-Sleep -Milliseconds 500 } Get-Process steam, steamwebhelper, steamservice, GameOverlayUI -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 Copy-Item -LiteralPath $download -Destination $target -Force Remove-Item -LiteralPath $download -Force } catch { Stop-Install '安装失败。' } Start-Process -FilePath (Join-Path $SteamPath 'Steam.exe') Write-Host '安装完成。'