windows 如何在远程机器上启动和停止服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/555693/
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
How can I start and stop services on a remote machine?
提问by David Segonds
I have a requirement in the project such that we have to stop a specific service say "x" in a remote machine (which is on the same LAN), change the registry key remotely and start the service again.
我在项目中有一个要求,即我们必须停止远程机器(位于同一 LAN 上)中的特定服务“x”,远程更改注册表项并再次启动该服务。
I tried the command sc \server stop service
, but I got the error:
我尝试了命令sc \server stop service
,但出现错误:
[SC] GetServiceKeyName FAILED 1060:
The specified service does not exist as an installed service.
[SC] 获取服务密钥名称失败 1060:
指定的服务不作为已安装的服务存在。
I am using Windows 2003 SP1. Are there any built in commands or APIs that are available on Windows?
我使用的是 Windows 2003 SP1。Windows 上是否有任何可用的内置命令或 API?
I need the commmand to run on the command prompt.
我需要在命令提示符下运行命令。
回答by Mark R.
Also keep in mind that the "service name" argument expected by the "sc" command line tool doesn't always equate to the name you see within the services control panel applet (which is the service "display name").
还要记住,“sc”命令行工具期望的“服务名称”参数并不总是等同于您在服务控制面板小程序中看到的名称(即服务“显示名称”)。
For example, the service that as appears "Adobe Acrobat Update Service" in my services control panel applet has an actual nameof "AdobeARMservice". You must use the latter, but not the former, when managing the service through the "sc" utility.
例如,在我的服务控制面板小程序中显示为“Adobe Acrobat 更新服务”的服务的实际名称为“AdobeARMservice”。通过“sc”实用程序管理服务时,您必须使用后者,而不是前者。
Example:
例子:
sc Stop "AdobeARMservice" (works)
sc Stop "Adobe Acrobat Update Service" (doesn't work)
To get the "real" name of a service, double-click its entry in the service control panel applet and see the "service name" field on the General tab.
要获取服务的“真实”名称,请在服务控制面板小程序中双击其条目,然后查看“常规”选项卡上的“服务名称”字段。
Of course in some cases, the display name and the service name are the same.
当然在某些情况下,显示名称和服务名称是相同的。
回答by David Segonds
You may want to look into PSToolsfrom SysInternals. Those tools are freely available and can help you manage processes on a remote Windows machine.
你可能想看看PSTools从Sysinternals的。这些工具是免费提供的,可以帮助您管理远程 Windows 机器上的进程。
The tools included in the PsTools suite, which are downloadable as a package, are:
PsTools 套件中包含的工具可作为包下载,包括:
PsExec - execute processes remotely PsFile - shows files opened remotely PsGetSid - display the SID of a computer or a user PsInfo - list information about a system PsKill - kill processes by name or process ID PsList - list detailed information about processes PsLoggedOn - see who's logged on locally and via resource sharing PsLogList - dump event log records PsPasswd - changes account passwords PsService - view and control services PsShutdown - shuts down and optionally reboots a computer PsSuspend - suspends processes PsUptime - shows you how long a system has been running since its last reboot
回答by gahooa
回答by sharptooth
Use OpenCSManager, then OpenService, then StartService.
使用 OpenCSManager,然后是 OpenService,然后是 StartService。