#include <windows.h>
#include <stdio.h>
BOOL CreateSampleService(LPCTSTR lpszDisplayName, LPCTSTR szPath)
{
TCHAR szPath[MAX_PATH];
if( !GetModuleFileName( NULL, szPath, MAX_PATH ) )
{
printf("GetModuleFileName failed (%d)\n", GetLastError());
return FALSE;
}
schService = CreateService(
schSCManager, TEXT("Sample_Srv"), lpszDisplayName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
if (schService == NULL)
{
printf("CreateService failed (%d)\n", GetLastError());
return FALSE;
}
else
{
CloseServiceHandle(schService);
return TRUE;
}
}
To find out how to write a service, this site may come in handy:
http://www.devx.com/cplus/Article/9857