Environment.MachineName 属性

获取此本地计算机的 NetBIOS 名称。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared ReadOnly Property MachineName As String
用法
Dim value As String

value = Environment.MachineName
public static string MachineName { get; }
public:
static property String^ MachineName {
    String^ get ();
}
/** @property */
public static String get_MachineName ()
public static function get MachineName () : String

属性值

包含此计算机的名称的字符串。

异常

异常类型 条件

InvalidOperationException

无法获取此计算机的名称。

备注

此计算机的名称是在系统启动期间从注册表中读取名称时建立的。如果此计算机是簇中的节点,则返回该节点的名称。

示例

下面的代码示例显示运行代码示例的计算机名。(出于安全原因,代码示例输出中省略了计算机名。)

' Sample for the Environment.MachineName property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  <-- Keep this information secure! -->
      Console.WriteLine("MachineName: {0}", Environment.MachineName)
   End Sub 'Main
End Class 'Sample
'
'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
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
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
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        //  <-- Keep this information secure! -->
        Console.WriteLine("MachineName: {0}", Environment.get_MachineName());
    } //main
} //Sample

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

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Environment 类
Environment 成员
System 命名空间