ProcessStartInfo.WindowStyle honored when UseShellExecute is false

Previously, WindowStyle was only honored when UseShellExecute was true. This change honors WindowStyle even when UseShellExecute is false.

Previous behavior

Prior to this change, the following code started the process as though WindowStyle hadn't been specified, because UseShellExecute = false. That is, the window was visible, not hidden.

using System.Diagnostics;

ProcessStartInfo startInfo = new()
{
    FileName = @"C:\Windows\System32\notepad.exe",
    UseShellExecute = false,
    WindowStyle = ProcessWindowStyle.Hidden
};

var process = Process.Start(startInfo);
process!.WaitForExit();

New behavior

Starting in .NET 8, WindowStyle is honored even for processes started with UseShellExecute = false.

The code from the Previous behavior section starts the process with the window hidden.

Version introduced

.NET 8 Preview 6

Type of breaking change

This change is a behavioral change.

Reason for change

Some scenarios require changing the style of the spawned process's window (especially to hide it).

This change affects code that specified WindowStyle even when it wasn't properly supported. For example, WPF's order of event firing is now altered. To mitigate the breaking change, don't specify WindowStyle in ProcessStartInfo.

Affected APIs