How to bring focus to window by process name?

后端 未结 4 1040
梦毁少年i
梦毁少年i 2020-12-16 22:47

If I\'m understanding this correctly this code should capture the active window and keep it in focus. concentr.exe is the process name. How do I bring a window in focus base

4条回答
  •  温柔的废话
    2020-12-16 22:59

    Have you thought of using the Window Name? I've found this bit of code to work great and not take up a lot of space:

    $wshell = New-Object -ComObject wscript.shell
    $wshell.AppActivate('New Tab - Google Chrome')
    

    Also, if you need to just Alt-TAB back to the last thing that ran (ie: you need focus to come back to the script window after firing something off) try this:

    $wshell = New-Object -ComObject wscript.shell
    $wshell.SendKeys('%{TAB}')
    

提交回复
热议问题