How to set foreground Window from Powershell event subscriber action

Posted by guillermooo on Stack Overflow See other posts from Stack Overflow or by guillermooo
Published on 2010-03-31T22:18:38Z Indexed on 2010/04/01 12:53 UTC
Read the original article Hit count: 1440

I have a FileSystemWatcher instance running in the background of my PoSh session watching for changes to text files. A PoSh event subscriber is attached to this event and, when fired, it launches a console program by calling Start-Process. This program steals de focus from the current foreground window (my PoSh console). Calling SetForegroundWindow from the PoSh event subscriber to return the focus to my PoSh console doesn't work. SwitchToThisWindow does work most of the time, but according to the MSDN docs, it shoulnd't be used.

Can I prevent Start-Process from stealing the focus in this situation or set it back from the event subscriber to the window that had it before this event is fired?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about events