Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created July 13, 2020 19:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jfversluis/633a6e0090ccf17d24740b7f38a8f98f to your computer and use it in GitHub Desktop.
param(
[Parameter()]
[Int32]$attempts = 3,
[Parameter()]
[Int32]$sleep = 10,
[Parameter()]
[bool]$keepAlive = $false
)
try {
$Win32ShowWindowAsync = Add-Type -MemberDefinition @"
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
"@ -name "Win32ShowWindowAsync" -Namespace Win32Functions -PassThru
} catch {}
Write-Output "Hiding GoXLR Windows...";
while (($attempts -gt 0) -or ($keepAlive -eq $true)) {
# Get All GoXLR Desktop processes and find one with a window handle
(Get-Process -Name "GOXLR APP*").MainWindowHandle | ForEach-Object {
if($_ -eq 0) { return; } # We can ignore processes spun up that have no window
Write-Output "Found a GoXLR Window... Closing it now.";
# We'll Hide the window through its handle
$Win32ShowWindowAsync::ShowWindowAsync($_, 0) | Out-Null
}
Write-Output "Attempts remaining: $attempts, sleeping for $sleep, keep alive: $keepAlive"
if($keepAlive -eq $false) {
$attempts--;
}
Start-Sleep -Seconds $sleep
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment