Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question