Export (0) Print
Expand All

ProcessStartInfo.CreateNoWindow Property

Gets or sets a value indicating whether to start the process in a new window.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public bool CreateNoWindow { get; set; }
/** @property */
public boolean get_CreateNoWindow ()

/** @property */
public void set_CreateNoWindow (boolean value)

public function get CreateNoWindow () : boolean

public function set CreateNoWindow (value : boolean)

Property Value

true to start the process without creating a new window to contain it; otherwise, false. The default is false.

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
	/// <summary>
	/// Shell for the sample.
	/// </summary>
	class MyProcess
	{
		// These are the Win32 error code for file not found or access denied.
		const int ERROR_FILE_NOT_FOUND =2;
		const int ERROR_ACCESS_DENIED = 5;

		/// <summary>
		/// Prints a file with a .doc extension.
		/// </summary>
		void PrintDoc()
		{
			Process myProcess = new Process();
			
			try
			{
				// Get the path that stores user documents.
				string myDocumentsPath = 
					Environment.GetFolderPath(Environment.SpecialFolder.Personal);

				myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; 
				myProcess.StartInfo.Verb = "Print";
				myProcess.StartInfo.CreateNoWindow = true;
				myProcess.Start();
			}
			catch (Win32Exception e)
			{
				if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
				{
					Console.WriteLine(e.Message + ". Check the path.");
				} 

				else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
				{
					// Note that if your word processor might generate exceptions
					// such as this, which are handled first.
					Console.WriteLine(e.Message + 
						". You do not have permission to print this file.");
				}
			}
		}


		public static void Main()
		{
			MyProcess myProcess = new MyProcess();
			myProcess.PrintDoc();
		}
	}
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft