共用方式為


ProcessStartInfo.Verb 屬性

定義

取得或設定動詞命令 (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;
    }
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來列印指定的檔。 您可以使用空字串 (“”) 來指定預設動詞。 動詞範例包括 “Edit”、“Open”、“OpenAsReadOnly”、“Print” 和 “Printto”。 您應該只使用出現在 屬性所 Verbs 傳回之動詞集中的動詞。

當您使用 Verb 屬性時,當您設定 屬性的值 FileName 時,必須包含擴展名。 如果您手動輸入 屬性的值 Verb ,則檔名不需要有擴展名。

適用於

另請參閱