Add service C ++ code
// File name addserver. cpp
# Include <stdio. h>
# Include <windows. h>
# Include <winsvc. h>
Char servername [100];
Char serverinfo [100];
Char serverpath [100];
Int main (void)
{
Printf ("enter the service name :");
Scanf ("% s", & servername );
Printf ("enter the service description :");
Scanf ("% s", & serverinfo );
Printf ("enter the program path :");
Scanf ("% s", & serverpath );
SC _HANDLE manager = NULL;
SC _HANDLE service = NULL;
If (manager = OpenSCManager (NULL, NULL, SC _MANAGER_CREATE_SERVICE) = NULL)
{
Printf ("service opening error ");
}
Service = CreateService (manager, servername, serverinfo,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
Serverpath, 0, 0, 0, 0, 0 );
If (service)
Printf ("created successfully ");
Else
Printf ("failed to create ");
CloseServiceHandle (service );
CloseServiceHandle (manager );
Return 0;
}