다음을 통해 공유


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지정한 문서를 인쇄합니다. 기본 동사는 빈 문자열("")을 사용하여 지정할 수 있습니다. 동사의 예로는 "Edit", "Open", "OpenAsReadOnly", "Print", "Printto"가 있습니다. 속성에서 반환 Verbs 된 동사 집합에 표시되는 동사만 사용해야 합니다.

속성을 사용하는 Verb 경우 속성 값을 FileName 설정할 때 파일 이름 확장명을 포함해야 합니다. 속성 값을 수동으로 입력하는 경우 파일 이름에 Verb 확장명이 필요하지 않습니다.

적용 대상

추가 정보