开发者

Determine from within code which user my process is running as

There's really no pressing reason for me to ask this question other than curiosity - using C#, is there a way to determine from within code which user my process is running as? To illustrate using code:

static void Main(string[] args)
{
  str开发者_如何学运维ing userID;
  //what goes here to fill in this userID variable?
  Console.out.WriteLine(string.Format("This process is running as {0}.", userID));
}


string userID = WindowsIdentity.GetCurrent().Name

From MSDN: WindowsIdentity.GetCurrent() and WindowsIdentity.Name


string UserID = Environment.UserName;


There are a variety of ways, depending on what type of application you're running.

Here's an article on using the Thread Principal to check user data / authorization.

This thread contains a couple of other approaches, though not much elaboration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜