Environment.MachineName プロパティ

定義

ローカル コンピューターの NetBIOS 名を取得します。Gets the NetBIOS name of this local computer.

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

プロパティ値

このコンピューターの名前を格納している文字列。A string containing 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
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.

セキュリティ

EnvironmentPermission
COMPUTERNAME 環境変数への読み取りアクセスを許可します。for read access to the COMPUTERNAME environment variable. 関連付けられた列挙型: ReadAssociated enumeration: Read

適用対象