Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Environment.MachineName Property

Definition

Namespace:
System
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Runtime.Extensions.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
Environment.Unix.cs
Source:
Environment.Unix.cs
Source:
Environment.Unix.cs
Source:
Environment.Unix.cs
Source:
Environment.Unix.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the NetBIOS name of this local computer.

public:
 static property System::String ^ MachineName { System::String ^ get(); };
public static string MachineName { get; }
static member MachineName : string
Public Shared ReadOnly Property MachineName As String

Property Value

The name of this computer.

Exceptions

The name of this computer cannot be obtained.

Examples

The following example displays the name of the computer that runs the code example. (The machine name is omitted from the example output for security reasons.)

// Sample for the Environment.MachineName property
using System;

class Sample
{
 public static void Main()
 {
 Console.WriteLine();
// <-- Keep this information secure! -->
 Console.WriteLine("MachineName: {0}", Environment.MachineName);
 }
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked "!---OMITTED---!".)

MachineName: !---OMITTED---!
*/
// Sample for the Environment.MachineName property
open System

// <-- Keep this information secure! -->
printfn $"\nMachineName: {Environment.MachineName}"

// This example produces the following results:
// (Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked "!---OMITTED---!".)
//
// MachineName: !---OMITTED---!
' Sample for the Environment.MachineName property
Class Sample
 Public Shared Sub Main()
 Console.WriteLine()
 ' <-- Keep this information secure! -->
 Console.WriteLine("MachineName: {0}", Environment.MachineName)
 End Sub
End Class
'
'This example produces the following results:
'(Any result that is lengthy, specific to the machine on which this sample was tested, 
'or reveals information that should remain secure, has been omitted 
'and marked "!---OMITTED---!".)
'
'MachineName: !---OMITTED---!
'

Remarks

The name of this computer is established at system startup when the name is read from the registry. If this computer is a node in a cluster, the name of the node is returned.

Applies to


Feedback

Was this page helpful?