Export (0) Print
Expand All

Environment.UserName Property

Gets the user name of the person who is currently logged on to the Windows operating system.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Shared ReadOnly Property UserName As String
'Usage
Dim value As String

value = Environment.UserName

/** @property */
public static String get_UserName ()

public static function get UserName () : String

Not applicable.

Property Value

The user name of the person who is logged on to Windows.

The UserName property provides part of the credentials associated with computer domain names, as returned by the UserDomainName property. This information is typically represented as DOMAIN\username.

This property can be used to identify the current user to the system and application for security or access purposes. It can also be used to customize a particular application for each user.

The following code example displays the user name of the person who started the current thread.

' Sample for the Environment.UserName property
Imports System

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

// Sample for the Environment.UserName property

import System.*;

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

UserName: !---OMITTED---!
*/

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft