Partager via


ProcessStartInfo.FileName Propriété

Définition

Obtient ou définit l’application ou le document à démarrer.

public:
 property System::String ^ FileName { System::String ^ get(); void set(System::String ^ value); };
public string FileName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string FileName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string FileName { get; set; }
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string FileName { get; set; }
[System.ComponentModel.SettingsBindable(true)]
public string FileName { get; set; }
member this.FileName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.FileName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.FileName : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.FileName : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
member this.FileName : string with get, set
Public Property FileName As String

Valeur de propriété

Nom de l’application à démarrer, ou nom d’un document d’un type de fichier associé à une application et qui a une action ouverte par défaut disponible. La valeur par défaut est une chaîne vide ( » « ).

Attributs

Exemples

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

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself.
                    // Given that it is started without a window so you cannot terminate it
                    // on the desktop, it must terminate itself or you can do it programmatically
                    // from this application using the Kill method.
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Public Shared Sub Main()
            Try
                Using myProcess As New Process()

                    myProcess.StartInfo.UseShellExecute = False
                    ' You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"
                    myProcess.StartInfo.CreateNoWindow = True
                    myProcess.Start()
                    ' This code assumes the process you are starting will terminate itself. 
                    ' Given that it is started without a window so you cannot terminate it 
                    ' on the desktop, it must terminate itself or you can do it programmatically
                    ' from this application using the Kill method.
                End Using
            Catch e As Exception
                Console.WriteLine((e.Message))
            End Try
        End Sub
    End Class
End Namespace

Remarques

Vous devez définir au moins la FileName propriété avant de démarrer le processus. Le nom de fichier est n’importe quelle application ou document. Un document est défini comme n’importe quel type de fichier qui a une action ouverte ou par défaut associée. Vous pouvez afficher les types de fichiers inscrits et leurs applications associées pour votre ordinateur à l’aide de la boîte de dialogue Options du dossier , disponible via le système d’exploitation. Le bouton Avancé mène à une boîte de dialogue qui indique s’il existe une action ouverte associée à un type de fichier inscrit spécifique.

L’ensemble de types de fichiers disponibles dépend en partie de la valeur de la UseShellExecute propriété. Si UseShellExecute c’est truele cas, vous pouvez démarrer n’importe quel document et effectuer des opérations sur le fichier, telles que l’impression, avec le Process composant. Quand UseShellExecute c’est falsele cas, vous pouvez démarrer uniquement des exécutables avec le Process composant.

Vous pouvez démarrer une application ClickOnce en définissant la FileName propriété sur l’emplacement (par exemple, une adresse web) à partir de laquelle vous avez initialement installé l’application. Ne démarrez pas une application ClickOnce en spécifiant son emplacement installé sur votre disque dur.

Important

L’utilisation d’une instance de ce type avec des données non approuvées est un risque de sécurité. Utilisez cet objet uniquement avec des données approuvées. Pour plus d’informations, consultez Valider toutes les entrées.

S’applique à