简体   繁体   中英

PowerShell: Kill and message prompt by window title

Is there a way in powershell to listen for message prompts produced by software that will terminate the message prompt?

For instance, if I am using an application and then it prompts a message for the user to click "OK". IS there a way I can use PowerShell to find that "window title" to kill that prompt?

I decided to go with AutoIt.

I noticed AutoIt has an AutoIt Window Info tool that you can hover you mouse over the Message Prompt. Then the Window Info will give you the Windows Title, Text and CLASS ID if it has one.

Then you can write a simple autoit script that will Wait for the message prompt and close it.

Example Script that I'm using.

WinWait("[CLASS:#32770]", "Cannot sign in to Lync because this sign-in address was not found. Please verify the sign-in address and try again. If the problem continues, please contact your support team.", 0)
WinClose( "Lync")

WinWait will wait for the prompt with that specific message and close it. Once it performs the action and closes the window. The EXE will shutdown and stop running, of course unless you program it not to close and loop.

You can use this two commands:

$TitleToKill = "CMD"

get-process | where-object {$_.MainWindowTitle -eq $TitleToKill} | stop-process

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM