Environment.UserName Property
.NET Framework 1.1
Gets the user name of the person who started the current thread.
[Visual Basic] Public Shared ReadOnly Property UserName As String [C#] public static string UserName {get;} [C++] public: __property static String* get_UserName(); [JScript] public static function get UserName() : String;
Property Value
The name of the person logged on to the system who started the current thread.
Remarks
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.
Example
[Visual Basic] ' 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---! ' [C#] // Sample for the Environment.UserName property using System; class Sample { public static void Main() { Console.WriteLine(); // <-- Keep this information secure! --> Console.WriteLine("UserName: {0}", Environment.UserName); } } /* 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---! */ [C++] // Sample for the Environment::UserName property #using <mscorlib.dll> using namespace System; int main() { Console::WriteLine(); // <-- Keep this information secure! --> Console::WriteLine(S"UserName: {0}", Environment::UserName); } /* 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---!".) UserName: !---OMITTED---! */
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- EnvironmentPermission for the ability to obtain the user name. Associated enumeration: EnvironmentPermissionAccess.Read