1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| int InstallService(void)
{
int ret = 1;
char strDir[1024];
SC_HANDLE schSCManager, schService;
GetCurrentDirectory(1024,strDir);
strcat(strDir,"\\exe.exe");
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (schSCManager != NULL)
{
LPCTSTR lpszBinaryPathName = strDir;
schService = CreateService( schSCManager,
"exe",
"exe",
SERVICE_ALL_ACCESS, // Type d'acces
SERVICE_WIN32_OWN_PROCESS, // Type de service
SERVICE_AUTO_START, // Pour le demarrage automatique
SERVICE_ERROR_NORMAL, // error control type
lpszBinaryPathName, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // Si null demarrer en tant que compte system
NULL); // Mot de passe : null si demarrer en tant que system
if (schService != NULL)
{
CloseServiceHandle(schService);
}
else
{
ret = 0;
}
}
else
{
ret = 0;
}
return ret;
} |
Partager