查找该帐户的服务被设置为QUOT&;登录为" [英] Find which account a service is set to "Log On As"

查看:140
本文介绍了查找该帐户的服务被设置为QUOT&;登录为"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找出用户帐户(本地系统/用户等 )服务被设置为根据(登录为)运行?

How to find out the user account (Local System/User etc) a service is set to run under ("Log On As")?

与此不同这code href="http://stackoverflow.com/questions/404144/what-account-is-my-service-running-as">类似的问题可以牛逼从服务本身和服务中运行可能没有运行。

Unlike this similar question this code can't run from within the service itself and the service may not be running.

的<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx">System.ServiceProcess.ServiceController类有用于获取状态,但不是登录为用户有用的方法。

The System.ServiceProcess.ServiceController class has useful methods for getting the status but not the "Log On As" user.

推荐答案

这是我所知道的,我发现它环顾四周,测试它,它工作的唯一途径。请确保您使用的服务名称不是它的显示名称,则还需要添加一个引用 System.Management

This is the only way I know of, I found it looking around and tested it, it works. Make sure you use the Service Name not it's Display Name, you will also need to add a reference to System.Management

string serviceName = "aspnet_state";

SelectQuery query = new System.Management.SelectQuery(string.Format(
    "select name, startname from Win32_Service where name = '{0}'", serviceName));
using (ManagementObjectSearcher searcher =
    new System.Management.ManagementObjectSearcher(query))
{
    foreach (ManagementObject service in searcher.Get())
    {
        Console.WriteLine(string.Format(
            "Name: {0} - Logon : {1} ", service["Name"], service["startname"]));
    }
}

这篇关于查找该帐户的服务被设置为QUOT&;登录为&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆