#include <windows.h>
#include <stdio.h>
#include "hash.h"
#include "debug.h"
#include "stdio.h"
#include "mytime.h"
#define SERV_NAME "GPRSServer"
//DWORD WINAPI Run( LPVOID lpParam );
DWORD WINAPI Run(char *argv0,char *argv1,char *argv2 ); //做实际工作的函数,需三个参数
static SERVICE_STATUS ServiceStatus;
static SERVICE_STATUS_HANDLE hStatus;
static SC_HANDLE schSCManager;
static SC_HANDLE schService;
void WINAPI ControlHandler(DWORD request)
{
switch(request) {
case SERVICE_CONTROL_STOP:
Log("service stopped!");
ServiceStatus.dwCurrentState=SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode=0;
break;
case SERVICE_CONTROL_PAUSE:
ServiceStatus.dwCurrentState=SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
ServiceStatus.dwCurrentState=SERVICE_RUNNING;
break;
case SERVICE_CONTROL_SHUTDOWN:
break;
case SERVICE_CONTROL_INTERROGATE:
break;
default:
break;
}
if(SetServiceStatus(hStatus,&ServiceStatus)==0)
fprintf(stderr, "SetServiceStatus in ControlHandler out Switch Error !/n");
return;
}
static void getServicePath(char *path)
{
LPQUERY_SERVICE_CONFIG lpsc;
LPSERVICE_DESCRIPTION lpsd;
DWORD dwBytesNeeded, cbBufSize, dwError;
// Get a handle to the SCM database.
schSCManager = OpenSCManager(
NULL, // local computer
NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights
if (NULL == schSCManager)
{
printf("OpenSCManager failed (%d)/n", GetLastError());
return;
}
// Get a handle to the service.
schService = OpenService(
schSCManager, // SCM database
SERV_NAME, // name of service
SERVICE_QUERY_CONFIG); // need query config acces