0

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
  • 21
  • 1
  • 4

1 Answers1

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
  • 4,589
  • 2
  • 7
  • 7
  • 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 Apr 02 '19 at 15:10
  • See the update I posted relative to the link you supplied here. – postanote Apr 03 '19 at 02:02