Environment.MachineName 屬性

定義

取得這個本機電腦的 NetBIOS 名稱。

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

屬性值

String

此電腦的名稱。

例外狀況

無法取得這個電腦的名稱。

範例

下列範例會顯示執行程式碼範例的電腦名稱稱。 (基於安全性考慮,電腦名稱稱會從範例輸出中省略。)

// 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---!
'

備註

從登錄讀取名稱時,會在系統啟動時建立此電腦的名稱。 如果這部電腦是叢集中的節點,則會傳回節點的名稱。

適用於