Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Environment.UserDomainName Property

Gets the network domain name associated with the current user.

[Visual Basic]
Public Shared ReadOnly Property UserDomainName As String
[C#]
public static string UserDomainName {get;}
[C++]
public: __property static String* get_UserDomainName();
[JScript]
public static function get UserDomainName() : String;

Property Value

The network domain name of the host computer.

Exceptions

Exception Type Condition
PlatformNotSupportedException The current operating system does not support retrieving the network domain name.
InvalidOperationException The network domain name cannot be retrieved.

Remarks

The value of this property is typically the host computer name, but can depend upon the application solution being deployed. The current user is the name specified in UserName.

Example

[Visual Basic] 
' 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---!
'

[C#] 
// 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---!
*/

[C++] 
// Sample for the Environment::UserDomainName property
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   //  <-- Keep this information secure! -->
   Console::WriteLine(S"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---!
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Environment Class | Environment Members | System Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.