Environment.MachineName Property
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
The name of this computer.
The name of this computer cannot be obtained.
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 namespace System;
int 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 S"!---OMITTED---!".)
MachineName: !---OMITTED---!
*/
// 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---!
'
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.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.5, 1.6, 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: