How to find a desktop window (by window name) in Windows 8.1 Update 2 OS, using the Win32 API FindWindow() in PowerShell environment?

后端 未结 4 991
鱼传尺愫
鱼传尺愫 2021-01-19 05:53

I don\'t remember having any problem finding a window in older Windows OS\'s, but, I\'m not succeeding in Windows 8.1 Update 2 OS, using PowerShell v4.0.

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 06:52

    It seems that the method doesn't fail if, and only if, the ClassName is also specified (cannot be null) like in this example:

    $sig=@'
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    '@    
    
    $w32 = Add-Type -Namespace Win32 -Name Funcs -MemberDefinition $sig -PassThru
    $w32::FindWindow('ConsoleWindowClass', 'Windows PowerShell') # Windows PowerShell Console
    

    If the ClassName is null, then the JPBlanc's method works correctly, which specifies a different signature for the method.

提交回复
热议问题