Using Sc.exe and Netsvc.exe to Control Services Remotely

Last reviewed: March 10, 1998
Article ID: Q166819
The information in this article applies to:
  • Microsoft Windows NT Workstation version 4.0
  • Microsoft Windows NT Server version 4.0

SUMMARY

Windows NT Server 4.0 Resource Kit Supplement 1, comes with two new administrative utilities to work remotely with Windows NT services.

The new utilities are:

  • Sc.exe: This tool provides a way to communicate with Service Controller (Services.exe) from the command prompt, to retrieve information about services.
  • Netsvc.exe: This tool provides a way to remotely start, stop, and query the status of services from the command line.

MORE INFORMATION

It is possible to use Sc.exe and Netsvc.exe to switch the start value of a service, and to remotely start and stop a service.

Using these resource kit utilities provides the ability to accomplish the registry change and ensure that the change is registered with the Services Control Manager. The Services Control Manager database is updated dynamically when using these utilities, allowing you to change the start values and stop and restart services remotely. Otherwise, the remote modification to the registry will require you to restart the remote computer or to make the change in the Services tool in Control Panel at the remote computer.

For a detailed explanation of the working of Service Control Manager, and the API set used, consult the Windows NT 4.0 Device Driver Kit (DDK), and the Windows NT 4.0 Software Development Kit (SDK).

An example of how to remotely change the start value of the Schedule service to disabled, test it for the disabled option, reset to manual, and then start the services follows.

In the example, the computer running the commands is MYMACHINE. The remote computer is REMOTE1. Administrative rights are required to perform the following commands on the remote computer:

   C:\>sc \\REMOTE1 config Schedule start= disabled
   [SC] ChangeServiceConfig SUCCESS

   C:\>netsvc /start \\REMOTE1  "Schedule"
   Error code 1058

   C:\net helpmsg 1058

The specified service is disabled and cannot be started.

   C:\>sc \\REMOTE1 config Schedule start= demand
   [SC] ChangeServiceConfig SUCCESS

   C:\>netsvc /start \\REMOTE1 "Schedule"
   Service is pending start on \\REMOTE1

   C:\>sc \\REMOTE1 qc Schedule
   [SC] GetServiceConfig SUCCESS

   SERVICE_NAME: Schedule
      TYPE               : 10  WIN32_OWN_PROCESS
      START_TYPE         : 3   DEMAND_START
      ERROR_CONTROL      : 1   NORMAL
      BINARY_PATH_NAME   : C:\WINNT\System32\AtSvc.Exe
      LOAD_ORDER_GROUP   :
      TAG                : 0
      DISPLAY_NAME       : Schedule
      DEPENDENCIES       :
      SERVICE_START_NAME : LocalSystem

You can automate the previous example through a batch file.

ADDITIONAL INFORMATION

Consult the Windows NT Server 4.0 Resource Kit, Supplement 1, for

additional information on the syntax and use of Sc.exe and Netsvc.exe.

Keywords          : ntreskit NTSrvWkst kbsetup
Version           : WinNT:4.0
Platform          : winnt
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 10, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.