简体   繁体   English

如何在远程计算机上启动和停止服务?

[英]How can I start and stop services on a remote machine?

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: [SC] GetServiceKeyName FAILED 1060:

The specified service does not exist as an installed service. 指定的服务不作为已安装的服务存在。

I am using Windows 2003 SP1. 我使用的是Windows 2003 SP1。 Are there any built in commands or APIs that are available on Windows? Windows上是否有可用的内置命令或API?

I need the commmand to run on the command prompt. 我需要在命令提示符下运行命令。

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 name of "AdobeARMservice". 例如,我的服务控制面板小程序中显示为“Adobe Acrobat Update Service”的服务的实际名称为“AdobeARMservice”。 You must use the latter, but not the former, when managing the service through the "sc" utility. 在通过“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. 当然,在某些情况下,显示名称和服务名称是相同的。

You may want to look into PSTools from SysInternals . 你可能想看看PSToolsSysinternals的 Those tools are freely available and can help you manage processes on a remote Windows machine. 这些工具是免费提供的,可以帮助您管理远程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

From this URL : 从这个URL

To stop a service remotely you can use the command sc.

Example:
> sc \\computer stop "Service Name"
> sc \\computer start "Service Name"

Perhaps you are missing a "\\" character? 也许你错过了一个“\\”字符?

使用OpenCSManager,然后使用OpenService,然后使用StartService。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用具有管理员权限的子进程停止和启动Windows服务? - How can i stop and start windows services using subprocess with admin permissions? 如何以编程方式停止/启动远程计算机上的计划任务? - How do I stop/start a scheduled task on a remote computer programmatically? 如何列出远程计算机文件夹的内容 - How I can list the contents of a folder of a remote machine 如何从远程 Windows 计算机检索机器名称? - How can I retrieve the machine name from a remote Windows computer? 如何在远程计算机上启动.cmd文件? - How can I launch .cmd files on a remote machine? EvtExportLog API 将远程机器的事件日志保存在远程 PC 本身中。 如何将其保存到主机 PC? - EvtExportLog API is saving eventlog of remote machine in remote PC itself. How can I save it to host PC? 如何使用PowerShell在IIS中停止和启动各个网站? - How can I stop and start individual websites in IIS using PowerShell? 如何在Windows下使用C ++在远程计算机上启动进程 - How to start a process on a remote machine in C++ under Windows 通过VB脚本停止/启动服务 - stop/start services by VB script 停止服务,运行批处理文件,然后启动服务 - Stop services, run batch files, then start services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM