How a running application can be set as active window via powershell?

0

1

To take screenshot of the desktop by this snippet, I want to be sure my application is in the captured image.

When that code runs per minute, How can I be sure my application would be in front of others? As the code is a Powershell snippet, I was thinking of mixing it with something to temporarily activate my application when it goes to take screenshot.

shal

Posted 2019-04-01T03:28:41.640

Reputation: 11

Answers

0

What have you tried?

Where is your code?

What errors are you having?

Native PowerShell is not designed to be a GUI management tool. You can do it, but there is no built-in cmdlet to do so.

You have to lean on either SendKeys, .Net, or 3rd Party add-on or tools.

Simple notepad example with SendKeys: (as long as your app is not minimized)... So, start notepad, click another app to ring it to foreground, then run the code below, which should brig notepad to the foreground.

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic") 
[Microsoft.VisualBasic.Interaction]::AppActivate((Get-Process -Name notepad).MainWindowTitle)

… if it is minimized, then that will not work. More code is needed to restore minimized windows. I'll leave that as a homework assignment for you.

postanote

Posted 2019-04-01T03:28:41.640

Reputation: 1 783

Thanks | What I tried is searching! I'm new in powershell scripting. I read some manuals and searched. So I couldn't implement it, then no error! | Mine is a simple loop calling that snippet as a function, described here: https://superuser.com/q/1419761/1014819 | Homework?! :'(

– shal – 2019-04-02T15:10:35.927

See the update I posted relative to the link you supplied here. – postanote – 2019-04-03T02:02:57.450