【问题标题】:Can't hide Internet Explorer window using PowerShell无法使用 PowerShell 隐藏 Internet Explorer 窗口
【发布时间】: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


【解决方案1】:

我发现将“Internet Explorer”替换为“IEFrame”时它可以工作。

它适用于以下行

[my.WinApi]::Hide("IEFrame", 'Google - Internet Explorer')

【讨论】:

  • 你还没有解释为什么你需要这样做。
  • 同上其他人的说法......您是在说一个特定的 IE/Edge 浏览器选项卡,还是您有多个 IE/Edge 实例可能与多个选项卡一起运行?
  • 我正在从事的项目中需要这个。这是关于关闭 IE 特定窗口,这段代码解决了我的问题。即使它适用于多个 IE 实例,也可以在 IE 运行多个选项卡时使用此特定窗口隐藏 IE 实例。谢谢大家。
猜你喜欢
  • 2021-08-26
  • 1970-01-01
  • 2014-02-01
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 2020-02-12
  • 1970-01-01
  • 2018-08-13
相关资源
最近更新 更多