无法使用 PowerShell 隐藏 Internet Explorer window
Can't hide Internet Explorer window using PowerShell
我正在尝试使用 PowerShell 隐藏 Internet Explorer windows 并尝试了不同的方法,但没有成功。我在 https://superuser.com/questions/1079133/run-a-windows-application-without-displaying-its-gui 找到了这段代码,这只适用于记事本。我需要帮助才能使此代码适用于 IE,即 Internet Explorer window 打开页面 Google。我想使用下面的代码隐藏这个 window。
$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 window。
我发现将 'Internet Explorer' 替换为 'IEFrame' 时它会起作用。
它适用于以下行
[my.WinApi]::Hide("IEFrame", 'Google - Internet Explorer')
我正在尝试使用 PowerShell 隐藏 Internet Explorer windows 并尝试了不同的方法,但没有成功。我在 https://superuser.com/questions/1079133/run-a-windows-application-without-displaying-its-gui 找到了这段代码,这只适用于记事本。我需要帮助才能使此代码适用于 IE,即 Internet Explorer window 打开页面 Google。我想使用下面的代码隐藏这个 window。
$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 window。
我发现将 'Internet Explorer' 替换为 'IEFrame' 时它会起作用。
它适用于以下行
[my.WinApi]::Hide("IEFrame", 'Google - Internet Explorer')