void InstallService(AnsiString ServiceName,
AnsiString ServiceDispName,
AnsiString ServiceFileName)
{
HANDLE SvcMgr;
HANDLE Svc;
SvcMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(!SvcMgr)
RaiseLastOSError();
try
{
Svc=CreateService(SvcMgr,ServiceName.c_str(),ServiceDispName.c_str(),
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS,
//SERVICE_AUTO_START
SERVICE_DEMAND_START
//SERVICE_DISABLED
,SERVICE_ERROR_NORMAL,
ServiceFileName.c_str(),NULL,NULL,NULL,NULL,NULL);
if(!Svc)RaiseLastOSError();
CloseServiceHandle(Svc);
}
__finally
{
CloseServiceHandle(SvcMgr);
}
}
--------------------------------