Created
November 30, 2016 20:01
-
-
Save dafzor/cb5710a93c54e61962ae0a093cae197a to your computer and use it in GitHub Desktop.
script to run the division and close uplay on exit
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
# powershell script to start thedivision and close uplay on exit by daf [ daf@madalien.com ] | |
# best run from PSRun.exe utility http://www.leporelo.eu/blog.aspx?id=run-scheduled-tasks-with-winform-gui-in-powershell | |
function Request-Close | |
{ | |
param([string]$name) | |
# code borrowed from http://stackoverflow.com/questions/14436916/gracefully-closing-a-process-in-a-remote-session | |
$src = @' | |
using System; | |
using System.Runtime.InteropServices; | |
public static class Win32 { | |
public static uint WM_CLOSE = 0x10; | |
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] | |
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); | |
} | |
'@ | |
Add-Type -TypeDefinition $src | |
$process = @(Get-Process $name)[0] | |
[Win32]::SendMessage($process.MainWindowHandle, [Win32]::WM_CLOSE, [IntPtr]::Zero, [IntPtr]::Zero) > $null | |
} | |
Start-Process "thedivision.exe" | |
Start-Sleep -s 30 # need to wait because thedivision.exe will die and launch uplay which will launch the real division... | |
Wait-Process -Name "thedivision" | |
#Stop-Process -Name "uplay" # can't use this because it leaves a ghost systray icon :( | |
Start-Sleep -s 1 # wait a bit else requesting uplay to close wont work | |
Request-Close "uplay" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment