简体   繁体   中英

Can't hide Internet Explorer window using PowerShell

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 ie 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM