Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 CreateNoWindow Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public Property CreateNoWindow As Boolean
Visual Basic (Usage)
Dim instance As ProcessStartInfo
Dim value As Boolean

value = instance.CreateNoWindow

instance.CreateNoWindow = value
C#
public bool CreateNoWindow { get; set; }
Visual C++
public:
property bool CreateNoWindow {
    bool get ();
    void set (bool value);
}
JScript
public function get CreateNoWindow () : boolean
public function set CreateNoWindow (value : boolean)

Property Value

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

If the UserName and Password properties are not nullNothingnullptra null reference (Nothing in Visual Basic), the CreateNoWindow property value is ignored and a new window is created.

Visual Basic
Imports System
Imports System.Diagnostics
Imports 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.
      Private ERROR_FILE_NOT_FOUND As Integer = 2
      Private ERROR_ACCESS_DENIED As Integer = 5


      '/ <summary>
      '/ Prints a file with a .doc extension.
      '/ </summary>
      Sub PrintDoc()
         Dim myProcess As New Process()

         Try
            ' Get the path that stores user documents.
            Dim myDocumentsPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal)

            myProcess.StartInfo.FileName = myDocumentsPath + "\MyFile.doc"
            myProcess.StartInfo.Verb = "Print"
            myProcess.StartInfo.CreateNoWindow = True
            myProcess.Start()
         Catch e As Win32Exception
            If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
               Console.WriteLine((e.Message + ". Check the path."))

            Else
               If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
                  ' 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."))
               End If
            End If
         End Try
      End Sub 'PrintDoc


      Public Shared Sub Main()
         Dim myProcess As New MyProcess()
         myProcess.PrintDoc()
      End Sub 'Main
   End Class 'MyProcess
End Namespace 'MyProcessSample

C#
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();
        }
    }
}

Visual C++
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// These are the Win32 error code for file not found or access denied.
#define ERROR_FILE_NOT_FOUND 2
#define ERROR_ACCESS_DENIED  5
int main()
{
   Process^ myProcess = gcnew Process;
   try
   {

      // Get the path that stores user documents.
      String^ myDocumentsPath = Environment::GetFolderPath( Environment::SpecialFolder::Personal );
      myProcess->StartInfo->FileName = String::Concat( 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( "{0}. Check the path.", e->Message );
      }
      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( "{0}. You do not have permission to print this file.", e->Message );
      }
   }

}


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
UseShellExecute vs. CreateNoWindow      Goatflats   |   Edit   |   Show History
If the UseShellExecute property is set to true, the CreateNoWindow property value is ignored and a new window is created.
Tags What's this?: Add a tag
Flag as ContentBug
Negative logic      JN2   |   Edit   |   Show History
Gotta love this property, I'm not very smart so I had to double check using MSDN.

Next time please call it CreateWindow...


/Jonas
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker