.NET
WindowStyle
CreateNoWindow
programming
C#

.NET - WindowStyle hidden vs. CreateNoWindow true?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

ProcessStartInfo.WindowStyle = Hidden and ProcessStartInfo.CreateNoWindow = true sound similar, but they are not the same setting. One asks for a window to start hidden if a window exists, and the other asks the process to start without creating a console window at all. Understanding that difference makes process-launch behavior much more predictable.

What WindowStyle = Hidden Means

WindowStyle is about the state of a window when the process starts. If you set it to ProcessWindowStyle.Hidden, you are saying, in effect, "if this process creates a window, start that window hidden."

csharp
1using System.Diagnostics;
2
3var info = new ProcessStartInfo
4{
5    FileName = "notepad.exe",
6    WindowStyle = ProcessWindowStyle.Hidden
7};
8
9Process.Start(info);

This makes sense for applications that normally create a visible window. It does not mean the process is running headless. It means the window is hidden.

What CreateNoWindow = true Means

CreateNoWindow is aimed at console-style processes. It tells the operating system not to create a new console window for the child process.

csharp
1using System.Diagnostics;
2
3var info = new ProcessStartInfo
4{
5    FileName = "cmd.exe",
6    Arguments = "/c echo hello",
7    UseShellExecute = false,
8    CreateNoWindow = true
9};
10
11Process.Start(info);

This is useful for background command-line work such as scripts, command invocations, and automation tasks where a console popup would be annoying.

The important condition is UseShellExecute = false. If shell execution is enabled, CreateNoWindow is ignored.

They Solve Different Problems

A quick way to think about it:

  • 'WindowStyle.Hidden is about window state'
  • 'CreateNoWindow is about console creation'

For a GUI app, WindowStyle.Hidden is the more relevant setting. For a console command launched in the background, CreateNoWindow = true is usually the more relevant one.

You can combine them:

csharp
1using System.Diagnostics;
2
3var info = new ProcessStartInfo
4{
5    FileName = "cmd.exe",
6    Arguments = "/c timeout /t 3",
7    UseShellExecute = false,
8    CreateNoWindow = true,
9    WindowStyle = ProcessWindowStyle.Hidden
10};
11
12Process.Start(info);

But in many console scenarios, CreateNoWindow is the setting that actually matters.

UseShellExecute Changes the Behavior

This is where many misunderstandings come from. UseShellExecute controls whether Windows launches the process through the shell. When it is true, several process-start options behave differently, and CreateNoWindow does not do what many people expect.

A common background-task setup looks like this:

csharp
1using System.Diagnostics;
2
3var info = new ProcessStartInfo
4{
5    FileName = "powershell.exe",
6    Arguments = "-File script.ps1",
7    UseShellExecute = false,
8    RedirectStandardOutput = true,
9    RedirectStandardError = true,
10    CreateNoWindow = true
11};
12
13using var process = Process.Start(info);
14string output = process.StandardOutput.ReadToEnd();
15string error = process.StandardError.ReadToEnd();
16process.WaitForExit();

This pattern is common because redirected streams also require UseShellExecute = false.

GUI Applications Still Have Their Own Rules

If you launch a real GUI application, CreateNoWindow does not magically turn it into a non-visual process. A GUI app can still create and manage its own windows. WindowStyle.Hidden is the property that more directly expresses "start hidden" for GUI scenarios.

Even then, the target application may not honor the request in every case. The launched program still controls its own UI behavior once running.

Choose the Setting Based on the Target Process

Use WindowStyle.Hidden when:

  • the target process is a GUI application
  • you want the window hidden rather than absent
  • shell-style launching is acceptable

Use CreateNoWindow = true when:

  • the target process is a console program
  • you do not want a console window to appear
  • you are already using UseShellExecute = false

That distinction covers most real-world cases.

Common Pitfalls

The biggest mistake is expecting CreateNoWindow = true to hide any kind of application window, including GUI windows. Another common issue is forgetting that CreateNoWindow is ignored when UseShellExecute is true. Developers also sometimes set both options without understanding which one is actually affecting the observed behavior. Finally, even WindowStyle.Hidden is still only a start request; the child process may later show UI on its own depending on how it is written.

Summary

  • 'WindowStyle.Hidden asks a process window to start hidden.'
  • 'CreateNoWindow = true prevents creation of a new console window for console-style processes.'
  • 'CreateNoWindow only works as expected when UseShellExecute = false.'
  • GUI apps and console apps respond to these settings differently.
  • Pick the setting based on the kind of process you are launching, not just on the words "hidden" and "no window."

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.