如何获取Windows服务域\用户名登录 [英] How to get Windows service Domain\Username it is logged in with
本文介绍了如何获取Windows服务域\用户名登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用下面的代码来获取服务器中的所有Windows服务.我想知道Domain \ User的详细信息,使用Windows服务登录.怎么能做到呢?
Hi,
I am using below code to get all the windows services in a server. I want to know the details of Domain\User, windows service is logged in with. How can achive this.
ServiceController[] lFnGetAllServicesInServer(string aStrServer)
{
ServiceController[] lArrObjServiceController = null;
try
{
lArrObjServiceController = ServiceController.GetServices(aStrServer.Trim());
return lArrObjServiceController;
}
catch (Exception ex)
{
return lArrObjServiceController;
}
finally
{
}
}
请帮忙
[edit]已添加代码块-OriginalGriff [/edit]
Please help out
[edit]Code block added - OriginalGriff[/edit]
推荐答案
解决了这个问题……
Got solved with this…
ManagementObjectSearcher lObjMSearcher =
new ManagementObjectSearcher(lStrRemotePath
, "select name, startname from Win32_Service where startname like ''DOMAINNAME''");
foreach (ManagementObject lObject in lObjMSearcher.Get())
{
string lStrServiceName = lObject["Name"].ToString();
string lStrDomain = lObject["startname"].ToString();
}
Thread.CurrentPrincipal.Identity.Name
应该给您用户名
should give you the username
这篇关于如何获取Windows服务域\用户名登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文