从服务中获取数据 [英] Fetching the data from Services

查看:101
本文介绍了从服务中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这是关于从服务(Windows控制台)获取数据。我在机器中有一些服务,我必须远程登录,并且必须打开并检查几个特定服务的状态,例如EX:在我们的任务管理器窗口中,我们有一个名为SERVICES的选项卡。在该选项卡中,我们将运行所有服务,并且在列旁边将提供状态Running,Stopped或者其他内容。



就像那样,我必须登录一些远程计算机并打开服务窗口(控制台窗口)并检查几项服务并更新Excel中的状态。我想自动化这个。



我对.Net很新。你有没有人建议我如何开始?

Hi All,

This is regarding fetching the data from Services (Windows Consoles). I have some of the services in the machines where i have to login remotely and have to open and check the status of few particular services like EX: In our Task Manager window, we have a tab called SERVICES. In that tab, we'll have all the services running and beside columns will provied the status Running, Stopped or something.

Like that, I have to login to some remote machine and open the Services window (Console Window) and check for few services and update the status in Excel. I would like to automate this.

I'm very new to .Net. Can you anyone suggest me how to start with this?

推荐答案

// needs a reference to System.ServiceProcess.dll
System.ServiceProcess.ServiceController[] services = System.ServiceProcess.ServiceController.GetServices("target-machine-name-or-IP-here");

foreach (System.ServiceProcess.ServiceController service in services)
{
    var machine = service.MachineName;
    var displayName = service.DisplayName;
    var status = service.Status;
}





显然,您运行代码的帐户需要所需的访问权限。



Obviously the account you run the code under needs the required access rights.


这篇关于从服务中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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