M
M
Maxim_Q2019-08-28 18:39:00
PowerShell
Maxim_Q, 2019-08-28 18:39:00

How to check from PowerShell if a window is active right now?

It is necessary to check whether the window is currently active or not. I can check if the process itself is running, but I don't know if the window is in the foreground or in the background. Please help me write some code. The internet is basically just how to activate the window, I can't find how to check its status.

$test = Get-Process | where {$_.MainWindowTitle} | where {$_.ProcessName -like "Test"}
If ($test) {
    # тут нужно дописать кусок кода для проверки статуса окна:
    #  ?
    #  $stat = ???
    #  ?
    #
     If ($stat) {
          Echo "Процесс запущен и окно на передмем плане, пользователь с ним работает"
     }
     else {
          Echo "Процесс запущен но окно на заднем плане, пользователь с ним не работает"
     }
}
else {
     Echo "Процесс не запущен"
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-08-28
@Maxim_Q

Get the title of the active (focused) window media... .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question