SendMessage is causing script to hang


I am having an issue where the SendMessage() function is causing a script to hang and thus never exiting though it is running the SendMessage like it should (Its task completes). Is there anyway to get around this because I am having a heck of a time killing it from the master script.


will not kill it. With out the force on remove-job it reports it cannot kill it because it is not finished.

I need to call this many times per day and each time I do it spawns a new powershell.exe eating about 30M of memory.

Note: The code will turn of your monitors if you run it and the “@ needs to be at the beginning of the line (can’t tab it over to look nice).

Also this hangs just the same without start-job so I do not believe it is related to start-job causes scripts to hang. MS Support. Further this is Win7Ent/2008R2.


Edit: Typos


Change SendMessage to PostMessage. It worked for me.

The difference is that PostMessage is asynchronous and it doesn’t have to wait for any response.


SendMessage is causing script to hang by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply