JSI Tip 6385. How do I configure service recovery on remote computers?
February 27, 2003
In tip 2516, we configured service recovery using the GUI.
The preferred method for configuring service recovery on a remote computer is to use SC.EXE from the Windows 2000 Resource Kit Supplement (which can be installed on Windows 2000 Professional).
The general syntax for using SC.EXE is:
sc [\ServerName] Command ServiceName [OptionName=OptionValue...]
Parameters
\ServerNameSpecifies the name of the server if you are running the commands on a remote computer. The name must start with two backslash characters (\). If you are running the commands on the local computer, do not supply this parameter.CommandSpecifies one of the following SC commands:
Config | Changes the configuration of a service (persistent). |
Continue | Sends a CONTINUE control request to a service. |
Control | Sends a control to a service. |
Create | Creates a service and adds it to the registry. |
Delete | Deletes a service from the registry. |
Description | Changes the description of a service. |
EnumDepend | Enumerates service dependencies. |
Failure | Changes the actions taken by a service upon failure. |
GetDisplayName | Gets the display name for a service. |
GetKeyName | Gets the name of the registry key for a service. |
Interrogate | Sends an INTERROGATE control request to a service. |
Pause | Sends a PAUSE control request to a service. |
Qc | Queries configuration for the service.To find out the name of the binary for any service and whether it shares a process with other services, run sc qc ServiceName. |
Qdescription | Queries the description of a service. |
Qfailure | Queries the actions taken by a service upon failure. |
Query | Queries the status for a service or enumerates the status for types of services. |
QueryEx | Queries the status and extended information for a service, or enumerates the status and extended information for types of services. |
SdShow | Displays a service's security descriptor using SDDL. |
SdSet | Sets a service's security descriptor using SDDL. |
Start | Starts a service. |
Stop | Sends a STOP request to a service. |
The following commands do not require a service name. Their syntax follows:
sc [ServerName] Command [OptionName=OptionValue...]
Boot | Values are {ok | bad} Indicates whether to save the last restart configuration as the last-known-good restart configuration. |
Lock | Locks the Service Database. |
QueryLock | Queries the LockStatus for the SCManager Database. |
ServiceNamespecifies the name given to the service key in the registry. This is different from the display name that you see in Service.exe. You can get the ServiceName from the display name by running:
sc GetKeyName DisplayName
OptionNamespecifies the name of an optional command parameter. You can supply from zero to any number of optional pairs of parameter names and values. For a list of available names, run:
sc Command
where Command is a valid command name as listed above.OptionValuespecifies the value for the parameter named by OptionName. For a list of available values, run:
sc Command
where Command is a valid command name as listed above.
Help Information at the Command Prompt
Using SC without parameters displays help for the tool. To display help for specific SC commands, use the following command prompt syntax:
sc Command
where Command is a valid command name other than Query or QueryEx.
The Query and QueryEx commands cause SC to list the status of all running services. For information about the Query and QueryEx commands, run the command sc, and at the prompt "Would you like to see help for the QUERY and QUERYEX commands?" type: y
When you type SC failure, you receive:
DESCRIPTION: Changes the actions upon failureUSAGE: sc failure [service name] ...OPTIONS: reset= (Must be used in conjunction with actions= ) reboot= command= actions= > (Must be used in conjunction with the reset= option)
You might configure the Task Scheduler on a remote computer as follows:
SC \ failure Schedule reset= 3600 reboot="Restarting do to Schedule failure" actions= restart/5000/restart/5000/reboot/1000
If you don't have the Resource Kit, you can manually configure the recovery and then export the service key. Here is an example of the Schedule service, after removing the unwanted Value Names and Keys:
REGEDIT4
[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSchedule]
"FailureCommand"=""
"FailureActions"=hex: 00,configuration,00
"RebootMessage"=""
To configure all the remote computers in your domains, you can use Computers.bat to pass the to the SC command or use Workstation.bat to run regedit /s filename.reg on the remote computers.
About the Author
You May Also Like