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"
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"