Environment.MachineName Property
Definition
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 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---!
'
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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應