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.
The following code works fine for me, thanks to @zyq's advice
[System.Windows.Forms.MessageBox]::Show('Test', 'PowerShell Dialog',
[Windows.Forms.MessageBoxButtons]::OK,
[Windows.Forms.MessageBoxIcon]::Information,
[Windows.Forms.MessageBoxDefaultButton]::Button1,
[Windows.Forms.MessageBoxOptions]::ServiceNotification
)
$Win32API = Add-Type -Name Funcs -Namespace Win32 -PassThru -MemberDefinition @'
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, IntPtr lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(IntPtr lpClassName, string lpWindowName);
'@
$Win32API::FindWindow('#32770', 'PowerShell Dialog')
$Win32API::FindWindow([IntPtr]::Zero, 'PowerShell Dialog')
$Win32API::FindWindow('#32770', [IntPtr]::Zero)
$Win32API::FindWindow('Notepad', [IntPtr]::Zero)