Environment.UserDomainName 属性

获取与当前用户关联的网络域名。

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

语法

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

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

属性值

主机的网络域名。

异常

异常类型 条件

PlatformNotSupportedException

该操作系统不支持检索网络域名。

InvalidOperationException

无法检索此网络域名。

备注

UserDomainName 属性首先尝试获取当前用户 Windows NT 4.0 帐户名的域名部分。帐户名格式为域名、“\”字符和用户名。如果该尝试失败,此属性将尝试获取与 UserName 属性提供的用户名相关联的域名。如果该尝试因主机未与域连接而失败,则返回主机名。

Windows 95、Windows 98、Windows 98 Second Edition、Windows Millennium Edition 平台说明: 此平台不支持 UserDomainName 属性。

示例

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

' Sample for the Environment.UserDomainName property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  <-- Keep this information secure! -->
      Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName)
   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---!".)
'
'UserDomainName: !---OMITTED---!
'
// Sample for the Environment.UserDomainName property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
//  <-- Keep this information secure! -->
    Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName);
    }
}
/*
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---!".)

UserDomainName: !---OMITTED---!
*/
// Sample for the Environment::UserDomainName property
using namespace System;
int main()
{
   Console::WriteLine();
   
   //  <-- Keep this information secure! -->
   Console::WriteLine( "UserDomainName: {0}", Environment::UserDomainName );
}

/*
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---!".)

UserDomainName: !---OMITTED---!
*/
// Sample for the Environment.UserDomainName property

import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        //  <-- Keep this information secure! -->
        Console.WriteLine("UserDomainName: {0}", 
            Environment.get_UserDomainName());
    } //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---!".)

UserDomainName: !---OMITTED---!
*/

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、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 命名空间