ProcessStartInfo.Verb 屬性

定義

取得或設定動詞命令 (Verb),用於開啟由 FileName 屬性所指定的應用程式或文件時。Gets or sets the verb to use when opening the application or document specified by the FileName property.

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

屬性值

對處理序所開啟的檔案所要採取的動作。The action to take with the file that the process opens. 預設值為空字串 (""),表示不採取任何動作。The default is an empty string (""), which signifies no action.

屬性

範例

下列程式碼範例會使用指定的動詞和檔案名,啟動新的進程。The following code example starts a new process by using the specified verb and file name. 這個程式碼範例是提供給 Verbs 屬性之較大範例的一部分。This code example is part of a larger example provided for the Verbs property.

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 屬性來取得。Each file name extension has its own set of verbs, which can be obtained by using the Verbs property. 例如,"print" 動詞會列印使用 FileName 所指定的檔。For example, the "print" verb will print a document specified by using FileName. 您可以使用空字串("")來指定預設動詞。The default verb can be specified by using an empty string (""). 動詞的範例包括「編輯」、「開啟」、「OpenAsReadOnly」、「列印」和「Printto」。Examples of verbs are "Edit", "Open", "OpenAsReadOnly", "Print", and "Printto". 您應該只使用出現在 Verbs 屬性所傳回的動詞集合中的動詞。You should use only verbs that appear in the set of verbs returned by the Verbs property.

當您使用 Verb 屬性時,當您設定 FileName 屬性的值時,必須包含副檔名。When you use the Verb property, you must include the file name extension when you set the value of the FileName property. 如果您手動輸入 [Verb] 屬性的值,檔案名就不需要有副檔名。The file name does not need to have an extension if you manually enter a value for the Verb property.

適用於

另請參閱