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

ProcessStartInfo.Verbs Property

Gets the set of verbs associated with the type of file specified by the FileName property.

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

public string[] Verbs { get; }
/** @property */
public String[] get_Verbs ()

public function get Verbs () : String[]

Property Value

The actions that the system can apply to the file indicated by the FileName property.

When you use the Verbs property, you must include the file name extension when you set the value of the FileName property. The file name extension determines the set of possible verbs.

The example displays the defined actions for the input file name. If the user selects one of the defined actions, the example starts a new process using the selected action and the input file name.

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.");
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.