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.
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.