Environment.UserName プロパティ

定義

現在のスレッドに関連付けられている人のユーザー名を取得します。

public:
 static property System::String ^ UserName { System::String ^ get(); };
public static string UserName { get; }
static member UserName : string
Public Shared ReadOnly Property UserName As String

プロパティ値

現在のスレッドに関連付けられているユーザーのユーザー名。

次の例では、現在のスレッドを開始したユーザーのユーザー名を表示します。

// Sample for the Environment::UserName property
using namespace System;
int main()
{
   Console::WriteLine();

   //  <-- Keep this information secure! -->
   Console::WriteLine( "UserName: {0}", Environment::UserName );
}
// 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);
    }
}
// Sample for the Environment.UserName property
open System

//  <-- Keep this information secure! -->
printfn $"\nUserName: {Environment.UserName}"
' Sample for the Environment.UserName property
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  <-- Keep this information secure! -->
      Console.WriteLine("UserName: {0}", Environment.UserName)
   End Sub
End Class

注釈

プロパティを UserName 使用すると、セキュリティまたはアクセスの目的で、システムとアプリケーションに対して、現在のスレッド上のユーザーを識別できます。 また、ユーザーごとに特定のアプリケーションをカスタマイズするために使用することもできます。

Windows では、プロパティは UserName Windows GetUserName 関数の呼び出しをラップします。 ユーザーのドメイン アカウントの資格情報は、ユーザーのドメイン名、'\' 文字、およびユーザー名として書式設定されます。 プロパティを UserDomainName 使用してユーザーのドメイン名を取得し、プロパティを UserName 使用してユーザー名を取得します。

Unix プラットフォームでは、 プロパティは UserName 関数の呼び出しを getpwuid_r ラップします。

ASP.NET アプリケーションが開発環境で実行されている場合、 プロパティは UserName 現在のユーザーの名前を返します。 発行された ASP.NET アプリケーションでは、このプロパティはアプリケーション プール アカウントの名前 (Default AppPool など) を返します。

適用対象

こちらもご覧ください