Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analyzing open windows by title in powershell/batch

I am trying to automate some processes with powershell/batch and want to wait for a window to pop up.

The window shows up in taskmgr but wont show via the tasklist command in the cmd, nor by get-process in powershell. Is there any way to do this?

Codes I've tried:

tasklist /v /fi "windowtitle eq Mapkey unterbrochen"
get-process
get-process xtop | format-list *

I want the window "Mapkey unterbrochen" to be found in a commmand. It shows up in taskmgr, so i guess it should be possible.

like image 569
Omglolyes Avatar asked Feb 17 '26 18:02

Omglolyes


1 Answers

You can use FindWindow from Win32 API:

$extlib = @"
  [DllImport("user32.dll", CharSet = CharSet.Unicode)]
  public static extern IntPtr FindWindow(IntPtr sClassName, String sAppName);
"@

$win32  = Add-Type -Namespace Win32 -Name Funcs -MemberDefinition $extlib -PassThru
$wname  = 'Mapkey unterbrochen' # any existing window name

$handle = $win32::FindWindow([IntPtr]::Zero, $wname ) 

if( $handle -gt 0 ) {
    # windows found
}
like image 161
f6a4 Avatar answered Feb 19 '26 11:02

f6a4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!