Is there any way we can start and stop the Win XP services programmatically. Will it be possible to write a .cmd or .bat file, which can be executed and the command prompt, to start and stop the services
Parameters
ServerName
Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.
ServiceName
Specifies the service name returned by the getkeyname operation.
ServiceArguments
Specifies service arguments to pass to the service to be started.
/?
Displays help at the command prompt.
Examples
The following example shows how you can use the sc start command:
sc start tapisrv
sc stop
Sends a STOP control request to a service.
Syntax
sc [ServerName] stop ServiceName
Parameters
ServerName
Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.
ServiceName
Specifies the service name returned by the getkeyname operation.
/?
Displays help at the command prompt.
Remarks
Not all services can be stopped.
Examples
The following example shows how you can use the sc stop command:
Start a registry editor (e.g., regedit.exe).
Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceB registry subkey.
Double-click DependOnService
Add ServiceA as a dependent service.
when I try to start a service using sc start ServiceA, it gives me this error
[SC] StartService: OpenService FAILED 1060:
The specified service does not exist as an installed service.
I have given the name whatever is visible under 'Display Name' in Services Window. I am able to start this service through the Services window, but not through a command script.
My Service B is dependent on Service A.
I am using the the following commands in a script to stop these services.
sc stop Service B
sc stop Service A
The second command fails with the following error
[SC] ControlService FAILED 1051:
A stop control has been sent to a service that other running services are dependent on.
How can I wait 'in the script' for the Service B to stop completely, before issuing the command to stop Service A
start /wait sc stop service B
start /wair sc stop Service A
Note:
The "start /wait" command runs the command (e.g. sc), then waits until the command actually terminates. Stopping and starting a service takes a while, so without this, the next command (e.g. sc stop Service A) may run before the sc stop Service B is actually stopped.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.