SendMessage is causing script to hang

前端 未结 3 1084
情书的邮戳
情书的邮戳 2021-01-06 01:21

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 comple

相关标签:
3条回答
  • 2021-01-06 01:34

    Short version of this script as a batch file command (put this line in a .bat file):

    @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)

    0 讨论(0)
  • 2021-01-06 01:45

    Please add

    Add-Type -Assembly UIAutomationClient
    

    and use

    public static extern IntPtr PostMessage(int hWnd, UInt32 hMsg, Int32 wParam, Int32 lParam);
    

    or

    public static extern IntPtr SendMessage(int hWnd, UInt32 hMsg, Int32 wParam, Int32 lParam);
    

    And the script will no longer crash

    0 讨论(0)
  • 2021-01-06 01:51

    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.

    0 讨论(0)
提交回复
热议问题