Export (0) Print
Expand All

Process::MachineName Property

Gets the name of the computer the associated process is running on.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

[MonitoringDescriptionAttribute(L"ProcessMachineName")]
[BrowsableAttribute(false)]
public:
property String^ MachineName {
	String^ get ();
}

Property Value

Type: System::String
The name of the computer that the associated process is running on.

ExceptionCondition
InvalidOperationException

There is no process associated with this Process object.

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.

NoteNote

When the associated process is executing on the local machine, this property returns a period (".") for the machine name. You should use the Environment::MachineName property to get the correct machine name.

To use the following example you must first start at least one instance of Notepad on a remote computer. 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.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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft