Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

ProcessStartInfo.CreateNoWindow Property

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

[Visual Basic]
Public Property CreateNoWindow As Boolean
[C#]
public bool CreateNoWindow {get; set;}
[C++]
public: __property bool get_CreateNoWindow();
public: __property void set_CreateNoWindow(bool);
[JScript]
public function get CreateNoWindow() : Boolean;
public function set CreateNoWindow(Boolean);

Property Value

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

Example

[Visual Basic] 
Imports System
Imports System.Diagnostics
Imports System.ComponentModel


Namespace MyProcessSample
    _
   '/ <summary>
   '/ Shell for the sample.
   '/ </summary>
   Public 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>
      Public 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>
    public 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>
        public 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();
        }
    }
}

[C++] 
#using <mscorlib.dll>
#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 = new Process();

    try {
        // Get the path that stores user documents.
        String* myDocumentsPath = 
            Environment::GetFolderPath(Environment::SpecialFolder::Personal);

        myProcess->StartInfo->FileName = String::Concat(myDocumentsPath, S"\\MyFile.doc"); 
        myProcess->StartInfo->Verb = S"Print";
        myProcess->StartInfo->CreateNoWindow = true;
        myProcess->Start();
    } catch (Win32Exception* e) {
        if (e->NativeErrorCode == ERROR_FILE_NOT_FOUND) {
            Console::WriteLine(S"{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(S"{0}. You do not have permission to print this file.", e->Message);
        }
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ProcessStartInfo Class | ProcessStartInfo Members | System.Diagnostics Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.