Skip to content

Instantly share code, notes, and snippets.

@Alistair1231
Last active March 26, 2023 22:28
Show Gist options
  • Save Alistair1231/1c3c28d4d89eff52fb8ccb301afa9e52 to your computer and use it in GitHub Desktop.
Save Alistair1231/1c3c28d4d89eff52fb8ccb301afa9e52 to your computer and use it in GitHub Desktop.
Playnite-Run-And-Close-Program

"Normal" App

execute before starting a game
$file1 = Start-Process "python3" "D:\path\file1.py" -Passthru
$file1 | Export-Clixml -Path (Join-Path D:\path 'file1-handle.xml')
execute after exiting a game
$file1 = Import-Clixml -Path (Join-Path D:\path 'file1-handle.xml')
$file1 | Stop-Process
Remove-Item "D:\path\file1-handle.xml"

App that uses admin

Note
I make use of powershell core and gsudo here. powershell 5 should work as well I think. gsudo is a tool that elevates the current shell. I install it using chocolatey.
choco install gsudo powershell-core (in admin shell)
execute before starting a game
$file2 = Start-Process "D:\path2\file2.exe" -Passthru
$file2 | Export-Clixml -Path (Join-Path D:\path2\ 'file2-handle.xml')
execute after exiting a game
$file2 = Import-Clixml -Path (Join-Path D:\path2 'file2-handle.xml')
sudo pwsh -NoProfile -c Stop-Process -Id $file2.Id
Remove-Item "D:\path2\file1-handle.xml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment