I'm trying to hide Internet Explorer windows using PowerShell and have tried different approaches but no luck. I've found this code at https://superuser.com/questions/1079133/run-a-windows-application-without-displaying-its-gui, This only works for Notepad. I need help to make this code work for IE i.e an internet explorer window is opened with page Google. I want to hide this window using below code.
$definition = @"
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public static void Show(string wClass, string wName)
{
IntPtr hwnd = FindWindow(wClass, wName);
if ((int)hwnd > 0)
ShowWindow(hwnd, 1);
}
public static void Hide(string wClass, string wName)
{
IntPtr hwnd = FindWindow(wClass, wName);
if ((int)hwnd > 0)
ShowWindow(hwnd, 0);
}
"@
add-type -MemberDefinition $definition -Namespace my -Name WinApi
[my.WinApi]::Hide('Internet Explorer', 'Google - Internet Explorer')
This code doesn't work to hide internet explorer window.
I've figured out that it works when replace 'Internet Explorer' with 'IEFrame'.
it worked with below line
[my.WinApi]::Hide("IEFrame", 'Google - Internet Explorer')