Share via


Process.MachineName 속성

정의

연결된 프로세스가 실행 중인 컴퓨터 이름을 가져옵니다.

public:
 property System::String ^ MachineName { System::String ^ get(); };
public string MachineName { get; }
[System.ComponentModel.Browsable(false)]
public string MachineName { get; }
member this.MachineName : string
[<System.ComponentModel.Browsable(false)>]
member this.MachineName : string
Public ReadOnly Property MachineName As String

속성 값

연결된 프로세스가 실행 중인 컴퓨터 이름입니다.

특성

예외

Process 개체와 연결된 프로세스가 없습니다.

예제

다음 예제를 사용하려면 먼저 원격 컴퓨터에서 하나 이상의 메모장 instance 시작해야 합니다. 이 예제에서는 메모장을 실행 중인 원격 컴퓨터의 이름을 요청한 다음 각 instance 대한 각 ProcessName, IdMachineName 속성을 표시합니다.

using System;
using System.Diagnostics;

class GetProcessesByNameClass
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Create notepad processes on remote computer");
        Console.Write("Enter remote computer name : ");
        string remoteMachineName = Console.ReadLine();

        if (remoteMachineName == null)
        {
            // Prepend a new line to prevent it from being on the same line as the prompt.
            Console.WriteLine(Environment.NewLine + "You have to enter a remote computer name.");
            return;
        }

        try
        {
            // Get all notepad processess into Process array.
            Process[] myProcesses = Process.GetProcessesByName("notepad", remoteMachineName);

            if (myProcesses.Length == 0)
                Console.WriteLine("Could not find notepad processes on remote computer.");

            foreach (Process myProcess in myProcesses)
            {
                Console.WriteLine(
                    $"Process Name : {myProcess.ProcessName}\n" +
                    $"Process ID   : {myProcess.Id}\n" +
                    $"MachineName  : {myProcess.MachineName}");
            }
        }
        catch (ArgumentException)
        {
            Console.WriteLine($"The value \'{remoteMachineName}\' is an invalid remote computer name.");
        }
        catch (InvalidOperationException)
        {
            Console.WriteLine("Unable to get process information on the remote computer.");
        }
        catch (PlatformNotSupportedException)
        {
            Console.WriteLine(
                "Finding notepad processes on remote computers " +
                "is not supported on this operating system.");
        }
    }
}
Imports System.Diagnostics

Class GetProcessesByNameClass

    'Entry point which delegates to C-style main Private Function
    Public Overloads Shared Sub Main()
        Main(Environment.GetCommandLineArgs())
    End Sub

    Public Overloads Shared Sub Main(ByVal args() As String)
        Console.WriteLine("Create notepad processes on remote computer")
        Console.Write("Enter remote computer name : ")
        Dim remoteMachineName As String = Console.ReadLine()

        If remoteMachineName Is Nothing Then
            ' Prepend a new line to prevent it from being on the same line as the prompt.
            Console.WriteLine(Environment.NewLine + "You have to enter a remote computer name.")
            Return
        End If

        Try
            ' Get all notepad processess into Process array.
            Dim myProcesses As Process() = Process.GetProcessesByName _
                                                ("notepad", remoteMachineName)
            If myProcesses.Length = 0 Then
                Console.WriteLine("Could not find notepad processes on remote computer.")
            End If
            Dim myProcess As Process
            For Each myProcess In myProcesses
                Console.WriteLine("Process Name : " & myProcess.ProcessName &
                            "  Process ID : " & myProcess.Id &
                            "  MachineName : " & myProcess.MachineName)
            Next myProcess
        Catch e As ArgumentException
            Console.WriteLine("The value '" & remoteMachineName & "' is an invalid remote computer name.")
        Catch e As PlatformNotSupportedException
            Console.WriteLine(
                "Finding notepad processes on remote computers " &
                "is not supported on this operating system.")
        Catch e As InvalidOperationException
            Console.WriteLine("Unable to get process information on the remote computer.")
        End Try
    End Sub
End Class

설명

원격 컴퓨터에서 실행되는 프로세스에 대한 통계 데이터 및 프로세스 정보를 볼 수 있지만 , CloseMainWindow또는 Kill 원격 컴퓨터에서는 호출Start할 수 없습니다.

참고

연결된 프로세스가 로컬 컴퓨터에서 실행되는 경우 이 속성은 컴퓨터 이름에 대한 마침표(".")를 반환합니다. 속성을 사용하여 Environment.MachineName 올바른 컴퓨터 이름을 가져와야 합니다.

적용 대상

추가 정보