Process.MachineName Property


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

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

Public ReadOnly Property MachineName As String

Property Value

Type: System.String

The name of the computer that the associated process is running on.

Exception Condition

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.


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.

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()
   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()
         ' 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


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

.NET Framework
Available since 1.1
Return to top