Environment.UserName 属性
获取启动当前线程的人的用户名。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Shared ReadOnly Property UserName As String
用法
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
属性值
启动当前线程的人登录系统所用的名称。
备注
该属性可用于识别系统和应用程序的当前用户(为了安全性或访问目的)。它还可用于为每个用户自定义特定的应用程序。
示例
下面的代码示例显示启动了当前线程的那个人的用户名。(出于安全原因,代码示例输出中省略了用户名。)
' 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 安全性
- EnvironmentPermission 用于获取用户名。关联的枚举:EnvironmentPermissionAccess.Read
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0