Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)
@Ma-XX-oN

This comment has been minimized.

Copy link

@Ma-XX-oN Ma-XX-oN commented Oct 20, 2021

Why is this using SendMessage? Wouldn't PostMessage be a better fit as you don't have to wait for a response, especially since you're sending to all top level windows, where all of which may not play nice?

@EugeneLoy

This comment has been minimized.

Copy link
Owner Author

@EugeneLoy EugeneLoy commented Oct 20, 2021

@Ma-XX-oN This piece of code originally came from stackoverflow. I copied it years back and I can't quite remember the source post. Anyway, it "just did the job" for me back then and I didn't give it much thought. If someone uses this, it is probably a good idea to take note of your comment.

@Ma-XX-oN

This comment has been minimized.

Copy link

@Ma-XX-oN Ma-XX-oN commented Oct 20, 2021

Well, if anyone wishes to have that code, here it is:

powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)

I found that using SendMessage resulted in the command to stall because it was waiting for a response.

@EugeneLoy

This comment has been minimized.

Copy link
Owner Author

@EugeneLoy EugeneLoy commented Oct 20, 2021

@Ma-XX-oN Thanks. I've updated the gist with your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment