BOOL CloseServiceHandle(SC_HANDLE Handle);
Le résultat est inutile.
#include <windows.h>
#include <winbase.h>
SC_HANDLE HandleGestionnaire;
SC_HANDLE HandleService;
Handle=OpenSCManager(NULL, NULL, GENERIC_EXECUTE);
if (!Handle)
{
...
}
...
HandleService=OpenService(HandleGestionnaire, "MonService", SERVICE_START);
if (!HandleService)
{
...
}
CloseServiceHandle(HandleService);
...
HandleService=OpenService(HandleGestionnaire, "MonService", QUERY_STATUS);
if (!HandleService)
{
...
}
CloseServiceHandle(HandleService);
...
HandleService=OpenService(HandleGestionnaire, "MonService", SERVICE_STOP);
if (!HandleService)
{
...
}
...
CloseServiceHandle(HandleService);
CloseServiceHandle(HandleGestionnaire);
Bien s'assurer que le service a été correctement ouvert.