检测 Windows 服务是否正在远程机器上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7972072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:53:11  来源:igfitidea点击:

Detect if Windows Service is running of remote machine

windowsservice

提问by MadSeb

Possible Duplicate:
Check status of services that run in a remote computer using C#

可能的重复:
使用 C# 检查在远程计算机中运行的服务的状态

Is it possible to check if a given windows service is running on a remote machine using C#?

是否可以使用 C# 检查给定的 Windows 服务是否在远程计算机上运行?

This is assuming that I have the correct login credentials for that machine.

这是假设我拥有该机器的正确登录凭据。

采纳答案by paulsm4

WMI, if you're using C# or VB.Net

WMI,如果您使用的是 C# 或 VB.Net

Otherwise, "SC" is probably the best tool to use from a command line or .bat file.

否则,“ SC”可能是从命令行或 .bat 文件使用的最佳工具。

回答by jdigital

Try this:

尝试这个:

sc \\<servername> query <servicename>

sc \\<servername> query <servicename>

回答by Roman R.

psservicefrom pstoolsdoes just this.

psservicefrompstools就是这样做的。

PsService is a service viewer and controller for Windows. Like the SC utility that's included in the Windows NT and Windows 2000 Resource Kits, PsService displays the status, configuration, and dependencies of a service, and allows you to start, stop, pause, resume and restart them. Unlike the SC utility, PsService enables you to logon to a remote system using a different account, for cases when the account from which you run it doesn't have required permissions on the remote system. PsService includes a unique service-search capability, which identifies active instances of a service on your network. You would use the search feature if you wanted to locate systems running DHCP servers, for instance.

PsService 是 Windows 的服务查看器和控制器。与包含在 Windows NT 和 Windows 2000 Resource Kits 中的 SC 实用程序一样,PsService 显示服务的状态、配置和相关性,并允许您启动、停止、暂停、恢复和重新启动它们。与 SC 实用程序不同,PsService 使您能够使用不同的帐户登录到远程系统,以防您运行它的帐户在远程系统上没有所需的权限。PsService 包括独特的服务搜索功能,可识别网络上服务的活动实例。例如,如果您想定位运行 DHCP 服务器的系统,您将使用搜索功能。