Bu yazdığım fonksiyon ile sisteme servis yükleyebilirsin.
"InstallSrvc" fonksiyonun parametrelerine bakarsan servisi yükleme seçeneklerini de ayarlaman mümkün.
Gerisi Bu kodu Delphi diline dönüştürmek, Sanırım forumda bunu yapacak bir forumdaş vardır.
Kolay gelsin
Yaşar
Kod: Tümünü seç
#include "Winsvc.h"
//----------------------------------------------------------------------------------------------------------------------------------------
BOOL InstallSrvc(wchar_t* pPath,
wchar_t* pDisplayName,
wchar_t* pSrvcName,
wchar_t* pDescription,
int StratType,
LPCWSTR DependOnService=NULL,
int Delay=0 )
{
SC_HANDLE schSCManager = OpenSCManagerW( NULL, NULL, SC_MANAGER_CREATE_SERVICE);
BOOL result = false;
if (schSCManager==NULL)
{
ErrorMsg(-10L,Lng["Svc8"]);
}
else
{
SC_HANDLE schService = CreateServiceW
(
schSCManager, /* SCManager database */
pSrvcName, /* name of service */
pDisplayName, /* service name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS| /* service type */
SERVICE_INTERACTIVE_PROCESS,
StratType, /* start type */
SERVICE_ERROR_IGNORE, /* error control type */
pPath, /* service's binary */
NULL, /* no load ordering group */
NULL, /* no tag identifier */
DependOnService, /* no dependencies */
NULL, /* LocalSystem account */
NULL /* no password */
);
if (schService==0)
{
ErrorMsg(-10L,Format((Lng["Svc9"]) ,OPENARRAY(TVarRec, (pSrvcName))));
}
else
{
//Servisin tanı mı.
SERVICE_DESCRIPTIONW sd;
if(pDescription != NULL)
{
sd.lpDescription = pDescription;
if(!ChangeServiceConfig2W(schService, SERVICE_CONFIG_DESCRIPTION, &sd) )
{
MessageBoxW(NULL,WStr(Format(Lng["Svc10"] ,
OPENARRAY(TVarRec, (pSrvcName)))), pSrvcName, 4096+16);
}
}
//Servisi geciktirme ile başlat
if(Delay != 0 )
{
SERVICE_FAILURE_ACTIONSW sdBuf={0};
sdBuf.lpRebootMsg=NULL;
sdBuf.dwResetPeriod=3600*24;
SC_ACTION action[3];
action[0].Delay=Delay*60000;
action[0].Type =SC_ACTION_RESTART;
action[1].Delay=action[0].Delay;
action[1].Type=SC_ACTION_REBOOT;
action[2].Delay=0;
action[2].Type=SC_ACTION_NONE;
sdBuf.cActions=3;
sdBuf.lpsaActions=action;
sdBuf.lpCommand=NULL;
ChangeServiceConfig2W(schService, SERVICE_CONFIG_FAILURE_ACTIONS, &sdBuf);
//Gecikmeli başlatmayı aktif et
SERVICE_DELAYED_AUTO_START_INFO info = { true };
ChangeServiceConfig2(schService, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &info);
}
result = true;
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return result;
}
//--------------------------------------------------------------------------