Freigeben über


ProcessStartInfo.Verbs-Eigenschaft

Ruft den Satz der Verben ab, der dem durch die FileName-Eigenschaft angegebenen Dateityp zugeordnet ist.

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

Syntax

'Declaration
Public ReadOnly Property Verbs As String()
'Usage
Dim instance As ProcessStartInfo
Dim value As String()

value = instance.Verbs
public string[] Verbs { get; }
public:
property array<String^>^ Verbs {
    array<String^>^ get ();
}
/** @property */
public String[] get_Verbs ()
public function get Verbs () : String[]

Eigenschaftenwert

Die Aktionen, die das System auf die durch die FileName-Eigenschaft angegebene Datei anwenden kann.

Hinweise

Wenn Sie die Verbs-Eigenschaft verwenden, müssen Sie beim Festlegen des Werts der FileName-Eigenschaft die Dateinamenerweiterung einschließen. Durch die Dateinamenerweiterung wird die Gruppe möglicher Verben bestimmt.

Beispiel

Im Beispiel werden die definierten Aktionen für den Eingabedateinamen angezeigt. Wenn der Benutzer eine der definierten Aktionen auswählt, wird im Beispiel ein neuer Prozess mit der ausgewählten Aktion und dem Eingabedateinamen gestartet.

Public Shared Sub PromptForProcessVerb(fileName As String)

   If Not (fileName Is Nothing) AndAlso fileName.Length > 0 Then
      ' Display the verbs associated with the input
      ' file name.
      Dim startInfo As ProcessStartInfo
      startInfo = New ProcessStartInfo(fileName)
      
      Dim i As Int32 = 1
      
      Console.WriteLine("Supported verbs associated with {0}: ", _
         fileName)
      
      Dim verb As String
      For Each verb In  startInfo.Verbs
         Console.WriteLine("  {0}. {1}", i.ToString(), verb)
         i += 1
      Next verb
      
      ' Check if the user wants to start the process with
      ' one of the verbs.
      If startInfo.Verbs.Length > 0 AndAlso _
         File.Exists(fileName) Then

         i = 0
         
         Console.Write("Select a verb using its index, ")
         Console.WriteLine("or press Enter to exit: ")
         Dim input As String = Console.ReadLine()
         
         If Not (input Is Nothing) AndAlso input.Length > 0 Then
            Try
               i = Int32.Parse(input)
            Catch e As FormatException
               i = 0
            End Try
         End If
         
         ' If the index is within range, start
         ' the process using the selected verb.
         If i > 0 AndAlso i <= startInfo.Verbs.Length Then

            Console.WriteLine("Type additional process/verb arguments or press Enter to exit: ")
            input = Console.ReadLine()

            startInfo.Verb = startInfo.Verbs((i - 1))
            Console.WriteLine()
            
            If Not input Is Nothing AndAlso input.Length > 0
                startInfo.Arguments = input
                Console.WriteLine("Starting process: {0} {1} {2}", _
                      startInfo.Verb, startInfo.FileName, startInfo.Arguments)
            Else
                Console.WriteLine("Starting process: {0} {1}", _
                    startInfo.Verb, startInfo.FileName)
            End If
            
            Dim newProcess As New Process()
            newProcess.StartInfo = startInfo
            
            Try
               newProcess.Start()
               
               Console.WriteLine("{0} started successfully with verb ""{1}""!", _
                   newProcess.ProcessName, startInfo.Verb)

            Catch e As System.ComponentModel.Win32Exception
               Console.WriteLine("  Win32Exception caught!")
               Console.WriteLine("  Win32 error = {0}", e.Message)

            Catch e As System.InvalidOperationException
                ' Catch this exception if the process exits quickly, 
                ' and the properties are not accessible.
                Console.WriteLine("File {0} started with verb {1}", _
                    startInfo.FileName, startInfo.Verb)

            End Try
         End If
      End If
   Else
      Console.WriteLine("Invalid or empty input file name.")
   End If
End Sub 
public static void PromptForProcessVerb(String fileName)
{
    if ((fileName != null) && (fileName.Length > 0))
    {
        // Display the verbs associated with the input
        // file name.

        ProcessStartInfo startInfo;
        startInfo = new ProcessStartInfo(fileName);

        Int32 i=1;

        Console.WriteLine("Supported verbs associated with {0}: ",
            fileName);

        foreach (String verb in startInfo.Verbs)
        {
            Console.WriteLine("  {0}. {1}", i.ToString(), verb);
            i++;
        }

        // Check if the user wants to start the process with
        // one of the verbs.
        if ((startInfo.Verbs.Length > 0) && (File.Exists(fileName)))
        {
            i = 0;

            Console.Write("Select a verb using its index, ");
            Console.WriteLine("or press Enter to exit: ");
            String input = Console.ReadLine();
                
            if ((input != null) && (input.Length > 0))
            {
                try 
                {
                    i = Int32.Parse(input);
                }
                catch (FormatException)
                {
                    i = 0;
                }
            }
            

            // If the index is within range, start
            // the process using the selected verb.

            if ((i > 0) && (i <= startInfo.Verbs.Length))
            {

                Console.WriteLine("Type additional process/verb arguments or press Enter to exit: ");
                input = Console.ReadLine();
 

                startInfo.Verb = startInfo.Verbs[i-1];
                Console.WriteLine();

                if ((input != null) && (input.Length > 0))
                {
                    startInfo.Arguments = input;
                    Console.WriteLine("Starting process: {0} {1} {2}", 
                        startInfo.Verb, startInfo.FileName, startInfo.Arguments);
                }
                else 
                {
                    Console.WriteLine("Starting process: {0} {1}", 
                        startInfo.Verb, startInfo.FileName);
                }

                Process newProcess = new Process();
                newProcess.StartInfo = startInfo;

                try 
                {
                    newProcess.Start();

                    Console.WriteLine(
                        "{0} started successfully with verb \"{1}\"!", 
                        newProcess.ProcessName, startInfo.Verb);
                }
                catch (System.ComponentModel.Win32Exception e)
                {
                    Console.WriteLine("  Win32Exception caught!");
                    Console.WriteLine("  Win32 error = {0}", 
                        e.Message);
                }
                catch (System.InvalidOperationException)
                {
                    // Catch this exception if the process exits quickly, 
                    // and the properties are not accessible.
                    Console.WriteLine("File {0} started with verb {1}",
                        startInfo.FileName, startInfo.Verb);
                }
            }
        }
    }
    else 
    {
        Console.WriteLine("Invalid or empty input file name.");
    }
}
void PromptForProcessVerb( String^ fileName )
{
   if ( (fileName != nullptr) && (fileName->Length > 0) )
   {
      
      // Display the verbs associated with the input
      // file name.
      ProcessStartInfo^ startInfo;
      startInfo = gcnew ProcessStartInfo( fileName );
      Int32 i = 1;
      Console::WriteLine( "Supported verbs associated with {0}: ", fileName );
      System::Collections::IEnumerator^ myEnum1 = startInfo->Verbs->GetEnumerator();
      while ( myEnum1->MoveNext() )
      {
         String^ verb = safe_cast<String^>(myEnum1->Current);
         Console::WriteLine( "  {0}. {1}", i, verb );
         i++;
      }
      
      // Check if the user wants to start the process with
      // one of the verbs.
      if ( (startInfo->Verbs->Length > 0) && (File::Exists( fileName )) )
      {
         i = 0;
         Console::Write( "Select a verb using its index, " );
         Console::WriteLine( "or press Enter to exit: " );
         String^ input = Console::ReadLine();
         if ( (input != nullptr) && (input->Length > 0) )
         {
            try
            {
               i = Int32::Parse( input );
            }
            catch ( FormatException^ ) 
            {
               i = 0;
            }

         }
         
         // If the index is within range, start
         // the process using the selected verb.
         if ( (i > 0) && (i <= startInfo->Verbs->Length) )
         {
            Console::WriteLine( "Type additional process/verb arguments or press Enter to exit: " );
            input = Console::ReadLine();
            startInfo->Verb = startInfo->Verbs[ i - 1 ];
            Console::WriteLine();
            if ( (input != nullptr) && (input->Length > 0) )
            {
               startInfo->Arguments = input;
               Console::WriteLine( "Starting process: {0} {1} {2}", startInfo->Verb, startInfo->FileName, startInfo->Arguments );
            }
            else
            {
               Console::WriteLine( "Starting process: {0} {1}", startInfo->Verb, startInfo->FileName );
            }
            Process^ newProcess = gcnew Process;
            newProcess->StartInfo = startInfo;
            try
            {
               newProcess->Start();
               Console::WriteLine( "{0} started successfully with verb \"{1}\"!", newProcess->ProcessName, startInfo->Verb );
            }
            catch ( System::ComponentModel::Win32Exception^ e ) 
            {
               Console::WriteLine( "  Win32Exception caught!" );
               Console::WriteLine( "  Win32 error = {0}", e->Message );
            }
            catch ( System::InvalidOperationException^ ) 
            {
               
               // Catch this exception if the process exits quickly, 
               // and the properties are not accessible.
               Console::WriteLine( "File {0} started with verb {1}", startInfo->FileName, startInfo->Verb );
            }

         }
      }
   }
   else
   {
      Console::WriteLine( "Invalid or empty input file name." );
   }
}

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

Siehe auch

Referenz

ProcessStartInfo-Klasse
ProcessStartInfo-Member
System.Diagnostics-Namespace
ProcessStartInfo.Verb-Eigenschaft