Process.MachineName プロパティ

定義

関連付けられたプロセスを実行しているコンピューターの名前を取得します。Gets the name of the computer the associated process is running on.

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

プロパティ値

関連付けられたプロセスを実行しているコンピューターの名前。The name of the computer that the associated process is running on.

属性

例外

この Process オブジェクトに関連付けられているプロセスはありません。There is no process associated with this Process object.

次の例を使用するには、まず、リモートコンピューター上でメモ帳のインスタンスを少なくとも1つ起動する必要があります。To use the following example you must first start at least one instance of Notepad on a remote computer. この例では、メモ帳が実行されているリモートコンピューターの名前を要求し、各インスタンスの ProcessNameId、および MachineName の各プロパティを表示します。The example requests the name of the remote computer on which Notepad is running, and then displays the respective ProcessName, Id, and MachineName properties for each instance.

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

注釈

リモートコンピューター上で実行されているプロセスの統計データとプロセス情報を表示できますが、リモートコンピューターで StartCloseMainWindow、または Kill を呼び出すことはできません。You can view statistical data and process information for processes running on remote computers but you cannot call Start, CloseMainWindow, or Kill on remote computers.

注意

関連付けられたプロセスがローカルコンピューター上で実行されている場合、このプロパティはコンピューター名のピリオド (".") を返します。When the associated process is executing on the local machine, this property returns a period (".") for the machine name. 正しいコンピューター名を取得するには、Environment.MachineName プロパティを使用する必要があります。You should use the Environment.MachineName property to get the correct machine name.

セキュリティ

LinkDemand
直前の呼び出し元に対する完全な信頼の場合。for full trust for the immediate caller. このメンバーは、部分的に信頼されているコードから使用することはできません。This member cannot be used by partially trusted code.

適用対象

こちらもご覧ください