从内部我的进程正在运行作为用户代码确定 [英] Determine from within code which user my process is running as
本文介绍了从内部我的进程正在运行作为用户代码确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有实在没有迫切的理由让我问比其他好奇这个问题 - 使用C#,有没有办法从内部我的进程正在运行作为用户代码来确定?为了说明使用代码:
静态无效的主要(字串[] args)
{
字符串userid;
//发生的事情在这里填写此用户ID变量?
Console.out.WriteLine(的String.Format(这个过程正在作为{0},用户ID));
}
解决方案
字符串userid = WindowsIdentity.GetCurrent()名称
从MSDN:的 WindowsIdentity.GetCurrent()并的 WindowsIdentity.Name
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)
{
string 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
这篇关于从内部我的进程正在运行作为用户代码确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文