XP下如何获得当前用户的名称?

jyj13 2005-02-05 07:05:43
XP下如何获得当前用户的名称?

谢谢先
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyuming2004 2005-02-06
  • 打赏
  • 举报
回复
或者:

System.Environment.GetEnvironmentVariable("username")
GX198302 2005-02-05
  • 打赏
  • 举报
回复
学习
程序的色彩 2005-02-05
  • 打赏
  • 举报
回复
MessageBox.Show(System.Environment.UserName);
xiongchen 2005-02-05
  • 打赏
  • 举报
回复
上面代码必须添加对System.EnterpriseServices的引用!
最简单的方法:
MessageBox.Show(System.Environment.UserName);
xiongchen 2005-02-05
  • 打赏
  • 举报
回复

下面这个方法可以获得当前登录域的用户名
using System;
using System.EnterpriseServices;
public string WhoIsCaller()
{
string retVal = "Unknown caller (Security is not enabled)";
if (ContextUtil.IsSecurityEnabled)
{
SecurityCallContext sc;
// CurrentCall is a static property which
// contains information about the current caller
sc = SecurityCallContext.CurrentCall;
// retrieve the current caller account name
retVal = sc.DirectCaller.AccountName;
}
return retVal;
}
其他的可以看看SecurityCallContext的成员
改用户信息是Admin的工作,既然是Admin,用AD用户管理来编辑不就行了,何必用你的程序。再说,这是系统级的东西,在应用程序这一级,恐怕没权限吧。
可以用role-based security来管理应用程序的用户,这是很flex很power的

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧