2

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

Bizhan
  • 16,157
  • 9
  • 63
  • 101
  • 2
    There is no command parameter for fullscreen, you need to either send a F11 to the window. Or you need to edit the config/registry to force edge to always be full screen at startup there is no other way. F11 still the easiest and you can use a powershell script to do it – Franck Jul 16 '19 at 15:27
  • Try this line of code to see whether it works as expected or not. System.Diagnostics.Process.Start(@"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", String.Join(" ", "maximized")); – Deepak-MSFT Jul 17 '19 at 07:05
  • @Deepak-MSFT it throws System.ComponentModel.Win32Exception: 'The system cannot find the file specified.' – Bizhan Jul 17 '19 at 08:06
  • I will try to find any other solution or work around and try to provide you soon. Thanks for your understanding. – Deepak-MSFT Jul 17 '19 at 08:07
  • @mofi I tried your solution but I was unsuccessful. I updated my question. – Bizhan Jul 17 '19 at 08:38
  • 1
    I also try to test with various other code example but nothing opens the Edge in maximize mode. The reason can be that MS Edge is UWP app. So it can be possible that UWP app has some different code to maximize it. You can try to ask on UWP forum and make a test to see whether it helps to maximize the Edge browser. FYI I also test the above code and it works with new Edge Chromium. – Deepak-MSFT Jul 19 '19 at 02:30
  • Try to use Webdriver: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp – Juanma Feliu Jun 17 '21 at 17:19

0 Answers0