I want to start Microsoft Edge with a given url and I want it to start in maximized state.
Based on this article we know that Process.Start(url)
does not work in .netcore. And based on this question Process.Start($"microsoft-edge:{url}")
does not always work.
Based on this answer, all I can do now is to tell cmd
to start the microsoft-edge
with the given url:
Process.Start("cmd", $"/c start microsoft-edge:http://localhost");
(edit:) Or I can use shellExecute:
Process.Start("shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge");
Which always gives me System.ComponentModel.Win32Exception: 'The system cannot find the file specified.'
when I specify arguments.
My goal is to find a way to change this line to maximize the Microsoft Edge on start.
Attempt #1
Process.Start(new ProcessStartInfo("cmd", $"/c start microsoft-edge:http://localhost")
{
WindowStyle = ProcessWindowStyle.Maximized,
CreateNoWindow = true
});
Clearly, changing the WindowStyle
here doesn't help at all, since it will maximize the cmd
window, which is then told not to show up.
Attempt #2
Process.Start(new ProcessStartInfo("cmd", $"/c start microsoft-edge:http://localhost -maximized")
{
CreateNoWindow = true
});
Also I was hoping that the Microsoft team put a simple maximized
argument into their brand new browser. But it didn't work.
Futile Attempt #3
Process.Start(new ProcessStartInfo("cmd", $"/c start microsoft-edge:http://localhost")
{
Arguments = "maximized",
CreateNoWindow = true
});
This too didn't work.
Edit:
Attempt #4
Based on this answer it is possible to signal the window via its handle:
private const int SW_MAXIMIZE = 3;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private static void Maximize()
{
//Thread.Sleep(1000); it makes a difference to wait here for IE to open but not for Edge
var items = Process.GetProcesses().Where(x=>x.ProcessName.Contains("MicrosoftEdge"));
foreach (var item in items)
{
ShowWindow(item.MainWindowHandle, SW_MAXIMIZE);
}
}
But none of the processes which has the MicrosoftEdge name handled that signal.
Attempt #5
using the ShellExecute:
Process.Start(@"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge");
It opens the browser, but it's not possible to send URL and parameters to it.
Any idea how to "open Edge in Maximized state" without sleeping the browser for 1 second and sending key-strokes?
I'm using .netcore 3.0.0-preview6-27804-01
and Windows10