Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft die zu startende Anwendung oder das zu startende Dokument ab oder legt die Anwendung bzw. das Dokument fest.
Namespace: System.Diagnostics
Assembly: System (in system.dll)
Syntax
'Declaration
Public Property FileName As String
'Usage
Dim instance As ProcessStartInfo
Dim value As String
value = instance.FileName
instance.FileName = value
public string FileName { get; set; }
public:
property String^ FileName {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_FileName ()
/** @property */
public void set_FileName (String value)
public function get FileName () : String
public function set FileName (value : String)
Eigenschaftenwert
Der Name der zu startenden Anwendung oder der Dokumentname eines einer Anwendung zugeordneten Dateityps, für den eine Standard-Open-Aktion verfügbar ist. Der Standardwert ist eine leere Zeichenfolge ("").
Hinweise
Vor dem Starten des Prozesses müssen Sie mindestens die FileName-Eigenschaft festlegen. Bei dem Dateinamen handelt es sich um eine beliebige Anwendung bzw. ein beliebiges Dokument. Ein Dokument ist hier als ein beliebiger Dateityp definiert, dem eine Open- oder Standardaktion zugeordnet ist. Sie können die für den Computer registrierten Dateitypen und die zugeordneten Anwendungen im Dialogfeld Ordneroptionen des Betriebssystems anzeigen. Die Schaltfläche Erweitert führt zu einem Dialogfeld, in dem angezeigt wird, ob einem bestimmten registrierten Dateityp eine Open-Aktion zugeordnet ist.
Die Menge der für Sie verfügbaren Dateitypen hängt teilweise vom Wert der UseShellExecute-Eigenschaft ab. Wenn UseShellExecute den Wert true aufweist, können Sie mit der Process-Komponente jedes Dokument öffnen und Operationen an der Datei ausführen, z. B. Drucken. Wenn UseShellExecute den Wert false aufweist, können Sie mit der Process-Komponente lediglich ausführbare Dateien starten.
Beispiel
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
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();
}
}
}
#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 );
}
}
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0
Siehe auch
Referenz
ProcessStartInfo-Klasse
ProcessStartInfo-Member
System.Diagnostics-Namespace