win32_set_service_status

Description

Informs the SCM of the current status of a running service.
This call is only valid for a running service process.

Parameters

status

The service status code, one of
WIN32_SERVICE_RUNNING,
WIN32_SERVICE_STOPPED,
WIN32_SERVICE_STOP_PENDING,
WIN32_SERVICE_START_PENDING,
WIN32_SERVICE_CONTINUE_PENDING,
WIN32_SERVICE_PAUSE_PENDING,
WIN32_SERVICE_PAUSED.

checkpoint

The checkpoint value the service increments periodically to report its
progress during a lengthy start, stop, pause, or continue operation.
For example, the service should increment this value as it completes
each step of its initialization when it is starting up.

The checkpoint is only valid when the
status is one of
WIN32_SERVICE_STOP_PENDING,
WIN32_SERVICE_START_PENDING,
WIN32_SERVICE_CONTINUE_PENDING or
WIN32_SERVICE_PAUSE_PENDING.

Return Values

Returns TRUE on success, FALSE if there is a problem with the parameters or a Win32 Error Code on failure.

User Contributed Notes 2 notes

On my Machine (Win XP SP2) the function "win32_get_last_control_message" never returns 4 so i will have to reply to 0 also.

finally after mixing several examples i now have a version working woithout filling my event log with errors:

<?php

/* * PHP SAMPLE TEMPLATE */

/* * APP MAIN FUNCTION * Called each second after the function last time finished * Should not take longer than max 20 seconds to execute * ELSE you should call NTServiceResponder(); at least each 20 secs * WARNING: NTServiceResponder will exit; if there was a STOP request */function Service_Main(){// YOU APPLICATION CODE HERE !!!sleep(1); // dummy something}

// Connect to service dispatcher and notify that startup was successfulif (!win32_start_service_ctrl_dispatcher($SERVICE_NAME)) die('Could not connect to service :'.$SERVICE_NAME);win32_set_service_status(WIN32_SERVICE_RUNNING);

So after much searching I finally found all the peices to make a working windows service & server including:- Installing & Uninstalling the service- Starting & Stopping the Service- Actually running a basic Server- Responding to windows Service to Stop/Start/Restart

I hope you find this useful! I did this using PHP 5.2 and the PECL library for 5.2 (PHP 5.3 at the time does not have a PECL Library compiled for it)

//Clean up and Exitwin32_set_service_status(WIN32_SERVICE_STOPPED);exit;

//*************** FUNCTIONS ***************function ShowHelp(){ echo "Usage: install:\t installs servce uninstall:\t deletes service start:\t\t Start the windows service stop:\t\t Stops the windows service run:\t\t called by CMS to run the service