我正在尝试使用 PowerShell 隐藏 Internet Explorer 窗口,并尝试了不同的方法,但没有成功。我在https://superuser.com/questions/1079133/run-a-windows-application-without-displaying-its-gui找到了这段代码,这只适用于记事本。我需要帮助才能使此代码适用于 IE,即打开一个带有 Google 页面的 Internet Explorer 窗口。我想使用下面的代码隐藏这个窗口。
$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')
此代码无法隐藏 Internet Explorer 窗口。
我发现当用“IEFrame”替换“Internet Explorer”时它可以工作。
它适用于以下行
[my.WinApi]::Hide("IEFrame", 'Google - Internet Explorer')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句