共用方式為


ProcessStartInfo.Verb 屬性

定義

取得或設定動詞,在開啟該屬性指定的 FileName 應用程式或文件時使用。

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

屬性值

程序開啟的檔案所採取的動作。 預設為空字串(“”),表示不執行任何動作。

屬性

範例

以下程式碼範例透過使用指定的動詞和檔案名稱啟動一個新程序。 此程式碼範例是該物業更大 Verbs 範例的一部分。

int i = 0;
var startInfo = new ProcessStartInfo(fileName);

// Display the possible verbs.
foreach (var verb in startInfo.Verbs)
{
    Console.WriteLine($"  {i++}. {verb}");
}

Console.Write("Select the index of the verb: ");
var indexInput = Console.ReadLine();
int index;
if (Int32.TryParse(indexInput, out index))
{
    if (index < 0 || index >= i)
    {
        Console.WriteLine("Invalid index value.");
        return;
    }

    var verbToUse = startInfo.Verbs[index];

    startInfo.Verb = verbToUse;
    if (verbToUse.ToLower().IndexOf("printto") >= 0)
    {
        // printto implies a specific printer. Ask for the network address.
        // The address must be in the form \\server\printer.
        // The printer address is passed as the Arguments property.
        Console.Write("Enter the network address of the target printer: ");
        var arguments = Console.ReadLine();
        startInfo.Arguments = arguments;
    }

    try
    {
        using (var newProcess = new Process())
        {
            newProcess.StartInfo = startInfo;
            newProcess.Start();

            Console.WriteLine($"{newProcess.ProcessName} for file {fileName} " +
                              $"started successfully with verb '{startInfo.Verb}'!");
        }
    }
    catch (Win32Exception e)
    {
        Console.WriteLine("  Win32Exception caught!");
        Console.WriteLine($"  Win32 error = {e.Message}");
    }
    catch (InvalidOperationException)
    {
        // Catch this exception if the process exits quickly,
        // and the properties are not accessible.
        Console.WriteLine($"Unable to start '{fileName}' with verb {verbToUse}");
    }
}
Dim i = 0
Dim startInfo = New ProcessStartInfo(fileName)

Dim verb As String
For Each verb In startInfo.Verbs
    ' Display the possible verbs.
    Console.WriteLine($"  {i}. {verb}")
    i += 1
Next

Console.Write("Select the index of the verb: ")
Dim indexInput = Console.ReadLine()
Dim index As Integer
If Int32.TryParse(indexInput, index) Then
    If index < 0 OrElse index >= i Then
        Console.WriteLine("Invalid index value.")
        Return
    End If

    Dim verbToUse = startInfo.Verbs(Convert.ToInt32(index))

    startInfo.Verb = verbToUse
    If verbToUse.ToLower().IndexOf("printto") >= 0 Then
        ' printto implies a specific printer.  Ask for the network address.
        ' The address must be in the form \\server\printer.
        Console.Write("Enter the network address of the target printer: ")
        Dim arguments = Console.ReadLine()
        startInfo.Arguments = arguments
    End If

備註

每個檔案副檔名都有自己的動詞集合,這些動詞可透過利用該 Verbs 屬性取得。 例如,動詞「print」會列印由 所 FileName指定的文件。 預設動詞可透過空字串(“”)來指定。 動詞的例子有「編輯」、「開放」、「OpenAsReadOnly」、「列印」和「列印」。 你應該只使用屬性回傳 Verbs 動詞集合中出現的動詞。

使用 Verb 屬性時,設定屬性 FileName 值時必須包含檔名副檔名。 如果你手動輸入屬性值 Verb ,檔名就不需要副檔名。

適用於

另請參閱