#include <windows.h>
#include <hbapi.h>
#define MY_SVC_NAME "My service"
#define THE_PROG "\"C:\\Program Files\\My software\\bin\\The Prog.exe\""
#define SLEEP_TIME 300000
static SERVICE_STATUS ServiceStatus;
static SERVICE_STATUS_HANDLE hStatus;
void WINAPI ServiceMain(DWORD argc, LPSTR argv);
void WINAPI ControlHandler(DWORD request);
void InitService();
static int cont_running = 1;
DWORD WINAPI ServiceHandlerProc(DWORD ControlCode, DWORD a, void *b, void *c)
{
switch (ControlCode) {
case SERVICE_CONTROL_STOP :
cont_running = 0;
ServiceStatus.dwCheckPoint=0;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
ServiceStatus.dwWaitHint =2000;
SetServiceStatus (hStatus, &ServiceStatus);
Sleep(1000);
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
break;
case SERVICE_CONTROL_SHUTDOWN :
cont_running = 0;
ServiceStatus.dwCheckPoint=0;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
ServiceStatus.dwWaitHint =2000;
SetServiceStatus (hStatus, &ServiceStatus);
Sleep(1000);
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
break;
}
return 0;
}
static void InitService( void )
{
cont_running=1;
do {
// system(THE_PROG);
Sleep(SLEEP_TIME);
} while (cont_running);
}
void WINAPI ServiceMain( DWORD argc, LPSTR argv )
{
SERVICE_STATUS_HANDLE hServiceStatus;
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
hServiceStatus = RegisterServiceCtrlHandlerEx( MY_SVC_NAME, ServiceHandlerProc, 0 );
Sleep( 1000 );
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus( hServiceStatus, &ServiceStatus );
// InitService();
MessageBeep( -1 );
MessageBeep( -1 );
MessageBeep( -1 );
return;
}
HB_FUNC( STARTSERVICECTRLDISPATCHER ) // cServiceName --> nError
{
SERVICE_TABLE_ENTRY ServiceStartTable[ 2 ];
ServiceStartTable[ 0 ].lpServiceName = MY_SVC_NAME;
ServiceStartTable[ 0 ].lpServiceProc = ( LPSERVICE_MAIN_FUNCTION ) ServiceMain;
ServiceStartTable[ 1 ].lpServiceName = NULL;
ServiceStartTable[ 1 ].lpServiceProc = NULL;
StartServiceCtrlDispatcher( ServiceStartTable );
hb_retni( GetLastError() );
}
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
StartServiceCtrlDispatcher()
MsgInfo( "ok" )
return nil
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 19 guests