You should do it the following way:
$iexplorer = new-object -com "InternetExplorer.Application"
$iexplorer.navigate("https://www.microsoft.com")
By default it creates invisible window.
If you need to make it visible you change the Boolean value:
$iexplorer.visible = $true
To make it invisible again just do:
$iexplorer.visible = $false
Edit C# invisible start - I'm pretty sure you will find it on SO
The following code should be enough:
ProcessStartInfo ieProcess = new ProcessStartInfo();
ieProcess.FileName = "iexplore.exe";
ieProcess.Arguments = "https://www.microsoft.com";
ieProcess.CreateNoWindow = true;
ieProcess.WindowStyle = ProcessWindowStyle.Hidden;
ieProcess.ErrorDialog = false;
Process.Start(ieProcess);
Edit 2 found another way to hide a window (if the above does not work
On MSDN I have found a ShowWindow function. I don't have means to try it now but you could do it the following way:
You will need ShowWindow
& FindWindow
.
In ShowWindows
function tehre are two values valid for your usecase.
Definition:
BOOL WINAPI ShowWindow(
_In_ HWND hWnd,
_In_ int nCmdShow
);
HWND - a handle to the window.
mCmdShow (int):
SW_HIDE 0 Hides the window and activates another window.
SW_SHOW 5 Activates the window and displays it in its current size and position.
For FindWindow
:
HWND WINAPI FindWindow(
_In_opt_ LPCTSTR lpClassName,
_In_opt_ LPCTSTR lpWindowName
);
Parameters
lpClassName [in, optional]
Type: LPCTSTR
The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the
low-order word of lpClassName; the high-order word must be zero.
If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or
RegisterClassEx, or any of the predefined control-class names.
If lpClassName is NULL, it finds any window whose title matches the
lpWindowName parameter.
lpWindowName [in, optional]
Type: LPCTSTR
The window name (the window's title). If this parameter is NULL, all window names match.
This is probably the lowest you can get. (source code inspired by technet solution)
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
// meaning defined above
const int SW_HIDE = 0;
const int SW_SHOW = 5;
static void Main()
{
Process ieProcess= new Process();
ieProcess.StartInfo.FileName = "iexplore.exe";
ieProcess.StartInfo.Arguments = "https://www.microsoft.com";
ieProcess.StartInfo.UseShellExecute = false;
ieProcess.StartInfo.CreateNoWindow = true;
ieProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ieProcess.StartInfo.LoadUserProfile = true;
ieProcess.Start();
//IntPtr hWnd = FindWindow(windowName, null);
IntPtr hWnd = FindWindow("Internet Explorer", null)
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, SW_HIDE); // Hide console window
ieProcess.WaitForExit(); // Tells you if the stdout or stderro should be synchronous or asynchronous
}
}
}