简体   繁体   中英

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.

I tried the command sc \\server stop service , but I got the error:

[SC] GetServiceKeyName FAILED 1060:

The specified service does not exist as an installed service.

I am using Windows 2003 SP1. Are there any built in commands or APIs that are available on Windows?

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").

For example, the service that as appears "Adobe Acrobat Update Service" in my services control panel applet has an actual name of "AdobeARMservice". You must use the latter, but not the former, when managing the service through the "sc" utility.

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 . Those tools are freely available and can help you manage processes on a remote Windows machine.

The tools included in the PsTools suite, which are downloadable as a package, are:

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 :

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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM