please dont rip this site Prev Next

ControlService info  Overview  Group

The ControlService function sends a control code to a Win32-based service.

BOOL ControlService(

    SC_HANDLE hService,

// handle to service

    DWORD dwControl,

// control code

    LPSERVICE_STATUS lpServiceStatus 

// pointer to service status structure



Identifies the service. This handle is returned by the OpenService or CreateService function. The access required for this handle depends on the dwControl code requested.
Specifies the requested control code. This value can be one of the standard control codes in the following table:




Requests the service to stop. The hService handle must have SERVICE_STOP access.


Requests the service to pause. The hService handle must have SERVICE_PAUSE_CONTINUE access.


Requests the paused service to resume. The hService handle must have SERVICE_PAUSE_CONTINUE access.


Requests the service to update immediately its current status information to the service control manager. The hService handle must have SERVICE_INTERROGATE access.


The ControlService function fails if this control code is specified.

This value can also be a user-defined control code, as described in the following table:



Range 128 to 255.

The service defines the action associated with the control code. The hService handle must have SERVICE_USER_DEFINED_CONTROL access.

Points to a SERVICE_STATUS structure to receive the latest service status information. The information returned reflects the most recent status that the service reported to the service control manager.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


The following error codes can be set by the service control manager. Other error codes can be set by the registry functions that are called by the service control manager.




The specified handle was not opened with the necessary access.


The service cannot be stopped because other running services are dependent on it.


The requested control code is not valid, or it is unacceptable to the service.


The requested control code cannot be sent to the service because the state of the service is SERVICE_STOPPED, SERVICE_START_PENDING, or SERVICE_STOP_PENDING.


The service has not been started.


The service did not respond to the start request in a timely fashion.


The ControlService function asks the service control manager to send the requested control code to the service. The service control manager sends the code if the service accepts the control and if the service is in a state in which a control can be sent to it. You cannot stop and start a service unless the security descriptor allows you to. The default security descriptor allows LocalSystem, Administrators, and Power Users to stop and start services. To change the security descriptor of a service, use SetServiceObjectSecurity.

The QueryServiceStatus or function returns a SERVICE_STATUS structure whose dwCurrentState and dwControlsAccepted members indicate the current state and controls accepted by a running service. All running services accept the SERVICE_CONTROL_INTERROGATE control code by default. Each service specifies the other control codes that it accepts when it calls the SetServiceStatus function to report its status. A service should always accept these codes when it is running, no matter what it is doing.

The following table shows the action of the service control manager in each of the possible service states:

Service state


Other controls























If the service accepts this control code, send the request to the service; otherwise, ControlService returns zero and GetLastError returns ERROR_INVALID_SERVICE_CONTROL.


The service is not in a state in which a control can be sent to it, so ControlService returns zero and GetLastError returns ERROR_SERVICE_CANNOT_ACCEPT_CTRL.


The service is not active, so ControlService returns zero and GetLastError returns ERROR_SERVICE_NOT_ACTIVE.

See Also

CreateService, OpenService, QueryServiceStatus, SetServiceObjectSecurity, SetServiceStatus, SERVICE_STATUS

file: /Techref/os/win/api/win32/func/src/f07_3.htm, 11KB, , updated: 2000/4/7 12:19, local time: 2024/7/20 00:07,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> ControlService</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!