Freigeben über


Environment.UserName-Eigenschaft

Ruft den Namen der Person ab, die den aktuellen Thread gestartet hat.

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

Syntax

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

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

Eigenschaftenwert

Der Name der beim System angemeldeten Person, die den aktuellen Thread gestartet hat.

Hinweise

Diese Eigenschaft kann zur Bekanntgabe des aktuellen Benutzers an das System oder an die Anwendung verwendet werden, wenn Sicherheits- oder Zugriffsfragen geregelt werden sollen. Sie kann auch zur Anpassung einer bestimmten Anwendung für jeden einzelnen Benutzer verwendet werden.

Beispiel

Im folgenden Codebeispiel wird der Benutzername der Person angezeigt, die den aktuellen Thread gestartet hat. (Der Benutzername wird in der Ausgabe des Codebeispiels aus Sicherheitsgründen weggelassen.)

' 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
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---!
*/
// Sample for the Environment::UserName property
using namespace System;
int 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 S"!---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---!
*/

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Environment-Klasse
Environment-Member
System-Namespace