Click to See Complete Forum and Search --> : creating a service


Paul Caseley
June 5th, 2003, 06:04 AM
I've written a simple service, it does nothing at the moment, but it will do..

Anyway I want to add the ability to install the service by running the service, e.g. "TestService.exe -install"

I've Done it but when i click on the service properties it gives me the error "Configuration Manager: A General Internal Error Occured"

now I cant find much information about this, I assume I need to handle the call from the service manager? any ideas?

this is the code I am using to install the service :


void Service::m_privateInstall()
{
SC_HANDLE schService;
SC_HANDLE schSCManager;

TCHAR szPath[512];

if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
{
printf("Unable to install\n");
return;
}

schSCManager = OpenSCManager(
NULL, // machine (NULL == local)
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);
if ( schSCManager )
{
schService = CreateService(
schSCManager, // SCManager database
this->m_GetServiceName(), // name of service
this->m_GetServiceName(), // name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
szPath, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
"", // dependencies
NULL, // LocalSystem account
NULL); // no password

if ( schService )
{
printf("%s installed.\n", this->m_GetServiceName() );
CloseServiceHandle(schService);
}
else
{
printf("CreateService failed\n");
}

CloseServiceHandle(schSCManager);
}
else
printf("OpenSCManager failed\n");
}

dudiav
June 12th, 2003, 11:29 AM
Hi,
use my Service Wizard (http://www.codeproject.com/useritems/ServiceWizard.asp) which is integrated with the Visual Studio IDE .It has install/uninstall features as well.