如何从窗口服务获取登录用户名 [英] how to get logged in user name from window service
本文介绍了如何从窗口服务获取登录用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从窗口服务获取登录用户名.当我使用 Environment.UserName 做同样的事情时,我得到的用户名是系统".
how to get logged in user name from window service. when i do the same thing using Environment.UserName i get username as "System".
谢谢阿文
推荐答案
您获得 System 因为您的服务在 System 帐户下运行.
You get System because your service runs under the System account.
有一篇关于 codeproject 的文章讨论了同样的事情.. 检查一下 http://www.codeproject.com/KB/vb/Windows_Service.aspx
There is an article on codeproject that discusses the same thing .. check it out http://www.codeproject.com/KB/vb/Windows_Service.aspx
System.Diagnostics.Process[] objArrProcess = System.Diagnostics.Process.GetProcessesByName("explorer");
string strCurrentUserName = objArrProcess[0].StartInfo.EnvironmentVariables["username"];
这对我有用.
这篇关于如何从窗口服务获取登录用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文