please dont rip this site Prev Next

StartService info  Overview  Group

The StartService function starts a service.

BOOL StartService(

    SC_HANDLE hService,

// handle of service

    DWORD dwNumServiceArgs,

// number of arguments

    LPCTSTR *lpServiceArgVectors 

// address of array of argument string pointers



Identifies the service. This handle is returned by the OpenService or CreateService function, and it must have SERVICE_START access.
Specifies the number of argument strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
Points to an array of pointers that point to null-terminated argument strings passed to a service. Driver services do not receive these arguments. If no arguments are passed to the service being started, this parameter can be NULL. The service accesses these arguments through its ServiceMain function. The first argument (argv[0]) is the name of the service by default, followed by the arguments, if any, in the lpServiceArgVectors array.

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. Others can be set by the registry functions that are called by the service control manager.




The specified handle was not opened with SERVICE_START access.


The specified handle is invalid.


The service binary file could not be found.


An instance of the service is already running.


The database is locked.


The service depends on a service that does not exist or has been marked for deletion.


The service depends on another service that has failed to start.


The service has been disabled.


The service could not be logged on.


The service has been marked for deletion.


A thread could not be created for the service.


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


When a driver service is started, the StartService function does not return until the device driver has finished initializing.

When a Win32-based service is started, the service control manager spawns the service process, if necessary. If the specified service shares a process with other services, the required process may already exist. The StartService function does not wait for the first status update from the new service, because it can take a while. Instead, it returns when the service control manager receives notification from the service control dispatcher that the ServiceMain thread for this service was created successfully.

The service control manager sets the following default status values before returning from StartService:

The calling process can determine if the new service has finished its initialization by calling the QueryServiceStatus function periodically to query the service’s status.

A service cannot call StartService during initialization. The reason is that the service control manager locks the service control database during initialization, so a call to StartService will block. Once the service reports to the service control manager that it has successfully started, it can call StartService.

See Also

ControlService, CreateService, OpenService, QueryServiceStatus, ServiceMain 

file: /Techref/os/win/api/win32/func/src/f87_4.htm, 7KB, , updated: 2000/4/7 11:19, local time: 2023/1/27 07:31,

 ©2023 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=""> StartService</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?


Welcome to!

Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.

Welcome to!