【发布时间】:2020-11-28 01:20:41
【问题描述】:
我正在尝试使用 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 窗口。
【问题讨论】:
-
听起来像是 XY 问题,可能吗?你在解决什么问题?
-
我想在一段时间内隐藏powershell脚本中的特定ie窗口。
-
为什么要在 PowerShell 脚本中隐藏特定的 IE 窗口?
-
它被称为“浏览器”是有原因的,如果你不能浏览它,你就不应该使用它。我同意以前的cmets。首先我们需要知道你想要达到的具体场景,你的 Windows 标题到底是什么,当你运行代码时会发生什么,(需要你的调试信息),以及什么在请求其他人帮助您之前,您已经尝试过自己解决问题。目前看起来好像您只是复制了一些代码,更改了两个字符串,并且完全没有做任何其他事情。请通过相应的编辑来改进您的问题。
标签: windows powershell internet-explorer winapi hide