param([string]$LogPath = "$env:TEMP\waiting-log.txt") function Write-Log($m){ try{"[$(Get-Date -Format o)] $m" | Out-File $LogPath -Append -Encoding UTF8}catch{} } try{ [System.Threading.Thread]::CurrentThread.TrySetApartmentState('STA') | Out-Null Add-Type -AssemblyName PresentationFramework | Out-Null $xaml = @' '@ $win = [Windows.Markup.XamlReader]::Parse($xaml) Write-Log "ShowDialog begin" $null = $win.ShowDialog() Write-Log "ShowDialog end" }catch{ Write-Log "FATAL: $($_.Exception.Message)`n$($_.Exception.StackTrace)" }