次の方法で共有


Environment.UserName プロパティ

現在のスレッドを開始した人のユーザー名を取得します。

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;

プロパティ値

現在のスレッドを開始した、システムにログオンしている人の名前。

解説

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

使用例

 
' 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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

Environment クラス | Environment メンバ | System 名前空間