列出并控制当前计算机/或远程计算机中的所有服务 [英] list and control all services in current machine/or remote machine
本文介绍了列出并控制当前计算机/或远程计算机中的所有服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,
您可以通过代码帮助我设计一个应用程序,以列出和控制当前计算机或远程计算机中的所有服务吗?
nimsss
解决方案
与Process几乎相同(请参见我对Processes问题的回答.
添加对程序集System.ServiceProcess
的引用.
使用 System.ServiceProcess; // .. 无效 DoWhatYouWantWithYourService(ServiceController控制器){ /* 一些代码*/ } foreach (在 ServiceController.GetServices()中,ServiceController控制器 DoWhatYouWantWithYourService(controller);
指定计算机还存在GetServices
的重载版本:
公共 静态 ServiceController [] GetServices( 字符串 machineName )
这是一个完整的答案.谁知道您想如何控制"您的服务?
这是一篇很棒的文章:
命令行Windows服务管理器 [这 [ ^ ]线程将是您从当前计算机检索所有服务的一种方式.
RegistryKey rk = Registry.LocalMachine; rk = rk.OpenSubKey(@"SYSTEM\CurrentControlSet\Services"); foreach (string keyName in rk.GetSubKeyNames()) { Console.WriteLine(keyName); }
希望对您有所帮助.
Sir,
Can you help me with code to design an application to list and control all services in current machine/or remote machine?
nimsss
解决方案
Pretty much the same way as with Process (see my answer to your question on Processes.
Add reference to assemblySystem.ServiceProcess
.
using System.ServiceProcess; //.. void DoWhatYouWantWithYourService(ServiceController controller) { /* some code */ } foreach (ServiceController controller in ServiceController.GetServices()) DoWhatYouWantWithYourService(controller);
There is also an overloaded version ofGetServices
for specified machine:
public static ServiceController[] GetServices( string machineName )
This is a complete answer. Who knows how do you want to "control" your services?
Here is an excellent article:
Command Line Windows Services Manager[^]
Regards
Espen Harlinn
Below code I found useful from THIS[^] thread would be a way for you to retrieve all the service from current machine.
RegistryKey rk = Registry.LocalMachine; rk = rk.OpenSubKey(@"SYSTEM\CurrentControlSet\Services"); foreach (string keyName in rk.GetSubKeyNames()) { Console.WriteLine(keyName); }
Hope it helps.
这篇关于列出并控制当前计算机/或远程计算机中的所有服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文