次の方法で共有


Process.MachineName プロパティ

関連付けられたプロセスを実行しているコンピュータの名前を取得します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public ReadOnly Property MachineName As String
'使用
Dim instance As Process
Dim value As String

value = instance.MachineName
public string MachineName { get; }
public:
property String^ MachineName {
    String^ get ();
}
/** @property */
public String get_MachineName ()
public function get MachineName () : String

プロパティ値

関連付けられたプロセスを実行しているコンピュータの名前。

例外

例外の種類 条件

InvalidOperationException

Process オブジェクトに関連付けられているプロセスがありません。

解説

リモート コンピュータで実行されているプロセスの統計データとプロセス情報は表示できますが、リモート コンピュータで StartCloseMainWindow、または Kill を呼び出すことはできません。

注意

関連付けられたプロセスがローカル マシンで実行されている場合、このプロパティはマシン名に対してピリオド (".") を返します。正しいマシン名を取得するには、Environment.MachineName プロパティを使用してください。

使用例

次の例を使用するには、最初に 1 つ以上のメモ帳のインスタンスをリモート コンピュータで開始しておく必要があります。この例は、メモ帳が動作しているリモート コンピュータの名前を要求し、次に各インスタンスに対して ProcessNameId、およびMachineName の各プロパティを表示します。

Imports System
Imports System.Diagnostics
Imports Microsoft.VisualBasic

Class GetProcessesByNameClass

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

   Public Overloads Shared Sub Main(ByVal args() As String)
      Try

         Console.Writeline("Create notepad processes on remote computer")
         Console.Write("Enter remote computer name : ")
         Dim remoteMachineName As String = Console.ReadLine()
         ' 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 SystemException
         Console.Write("Caught Exception .... : " & e.Message)
      Catch e As Exception
         Console.Write("Caught Exception .... : " & e.Message)
      End Try
   End Sub 'Main
End Class 'GetProcessesByNameClass
using System;
using System.Diagnostics;

class GetProcessesByNameClass
{
   public static void Main(string[] args)
   {
      try
      {

         Console.Write("Create notepad processes on remote computer \n");
         Console.Write("Enter remote computer name : ");
         string remoteMachineName = Console.ReadLine();
         // 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.Write("Process Name : " + myProcess.ProcessName + "  Process ID : "
               + myProcess.Id + "  MachineName : " + myProcess.MachineName + "\n");
         }

      }
      catch(SystemException e)
      {
         Console.Write("Caught Exception .... : " + e.Message);
      }
      catch(Exception e)
      {
         Console.Write("Caught Exception .... : " + e.Message);
      }
   }
}
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
int main()
{
   try
   {
      Console::Write( "Create notepad processes on remote computer \n" );
      Console::Write( "Enter remote computer name : " );
      String^ remoteMachineName = Console::ReadLine();
      
      // Get all notepad processess into Process array.
      array<Process^>^myProcesses = Process::GetProcessesByName( "notepad", remoteMachineName );
      if ( myProcesses->Length == 0 )
            Console::WriteLine( "Could not find notepad processes on remote computer." );
      Collections::IEnumerator^ myEnum = myProcesses->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Process^ myProcess = safe_cast<Process^>(myEnum->Current);
         Console::Write( "Process Name : {0}  Process ID : {1}  MachineName : {2}\n", myProcess->ProcessName, myProcess->Id, myProcess->MachineName );
      }
   }
   catch ( SystemException^ e ) 
   {
      Console::Write( "Caught Exception .... : {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::Write( "Caught Exception .... : {0}", e->Message );
   }

}

.NET Framework のセキュリティ

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

Process クラス
Process メンバ
System.Diagnostics 名前空間
GetProcesses
GetProcessById
GetProcessesByName