|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| No
| Win32s
| No
| Import Library
| advapi32.lib
| Header File
| winsvc.h
| Unicode
| WinNT
| Platform Notes
| None
|
|
|
StartService
The StartService function starts the execution of a service.
BOOL StartService(
SC_HANDLE hService,
| // handle of service
| DWORD dwNumServiceArgs,
| // number of arguments
| LPCTSTR *lpServiceArgVectors
| // address of array of argument string pointers
| );
|
|
Parameters
hService
Identifies the service. This handle is returned by the OpenService or CreateService function, and it must have SERVICE_START access.
dwNumServiceArgs
Specifies the number of argument strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
lpServiceArgVectors
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. Note that in the array of arguments passed to the 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.
Errors
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.
Value
| Meaning
| ERROR_ACCESS_DENIED
| The specified handle was not opened with SERVICE_START access.
| ERROR_INVALID_HANDLE
| The specified handle is invalid.
| ERROR_PATH_NOT_FOUND
| The service binary file could not be found.
| ERROR_SERVICE_ALREADY_RUNNING
| An instance of the service is already running.
| ERROR_SERVICE_DATABASE_LOCKED
| The database is locked.
| ERROR_SERVICE_DEPENDENCY_DELETED
| The service depends on a service that does not exist or has been marked for
deletion.
| ERROR_SERVICE_DEPENDENCY_FAIL
| The service depends on another service that has failed to start.
| ERROR_SERVICE_DISABLED
| The service has been disabled.
| ERROR_SERVICE_LOGON_FAILED
| The service could not be logged on.
| ERROR_SERVICE_MARKED_FOR_DELETE
| The service has been marked for deletion.
| ERROR_SERVICE_NO_THREAD
| A thread could not be created for the Win32 service.
| ERROR_SERVICE_REQUEST_TIMEOUT
| The service did not respond to the start request in a timely fashion.
|
Remarks
When a driver service is started, the StartService function does not return until the device driver has finished initializing.
When a 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
(which may 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:
- Current state of the service is set to SERVICE_START_PENDING.
- Controls accepted is set to none (zero).
- The CheckPoint value is set to zero.
- The WaitHint time is set to 2 seconds.
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
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|