Click here to Skip to main content
15,888,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: reading and writing xml files in vc++6.0 Pin
kir_MFC30-Jun-09 4:06
kir_MFC30-Jun-09 4:06 
QuestionRe: reading and writing xml files in vc++6.0 Pin
David Crow30-Jun-09 4:12
David Crow30-Jun-09 4:12 
QuestionUsing Class Template in Visual C++ [modified] Pin
emira6730-Jun-09 1:01
emira6730-Jun-09 1:01 
AnswerRe: Using Class Template in Visual C++ Pin
«_Superman_»30-Jun-09 1:08
professional«_Superman_»30-Jun-09 1:08 
AnswerRe: Using Class Template in Visual C++ Pin
Stuart Dootson30-Jun-09 2:39
professionalStuart Dootson30-Jun-09 2:39 
GeneralRe: Using Class Template in Visual C++ Pin
emira6730-Jun-09 2:48
emira6730-Jun-09 2:48 
GeneralRe: Using Class Template in Visual C++ Pin
Stuart Dootson30-Jun-09 2:52
professionalStuart Dootson30-Jun-09 2:52 
Questionerror in starting widows service after installation Pin
Subrat Patnaik30-Jun-09 0:46
Subrat Patnaik30-Jun-09 0:46 
hi all,
i have written a small service.now when i install the service, the service gets installed what i feel but is not able to start. using an installer i am installing the service application in windows vista.
it gives out an error during installation, when the service is getting started.
it throws an error as follows:
Create process failed: error code 14001. the application has failed to start because the application configuration is incorrect. reinstalling the application may fix the problem.

i tried reinstalling, however the same problem persists...

i am pasting the code below,, for initial main, service installation and service start functions..please can i get some help on fixing the error....

*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void __cdecl _tmain(int argc, char **argv)
{
HKEY hKeyHandle;
DWORD dwDataToWrite = 1;

if( argc == 3 )
{
printf("ERROR:\tIncorrect number of arguments\n\n");
return;
}
char *arg1 = argv[1];
char *arg2 = argv[2];

if(_strnicmp(arg1, "install", 7) == 0)
{
if(!PathFileExists(arg2 ))
{
exit(1);
}
if (InstallService(arg2))
{
MessageBox(NULL,"Service installed successfully",Message,MB_OK);
}
else
{
MessageBox(NULL,"Error in service installation",Message,MB_OK);
exit(2);
}
}
else if (lstrcmpi( arg1, TEXT("uninstall")) == 0 )
{
if(!ServiceDelete())
{
MessageBox(NULL,"Error in Un-installing",Message,MB_OK);
exit(3);
}
}
else if (lstrcmpi( arg1, TEXT("enable")) == 0 )
{
if (!EnableService())
{
MessageBox(NULL,"Error in enabling",Message,MB_OK);
exit(4);
}
}
else
exit(0);
SERVICE_TABLE_ENTRY DispatchTable[] = {
{ SRVCNAME, (LPSERVICE_MAIN_FUNCTION) SvcMain },
{ NULL, NULL } };

StartServiceCtrlDispatcher(DispatchTable);
}



// Service main function for the service

VOID WINAPI SvcMain(DWORD dwArgs,LPTSTR *lpszArgv)
{
DWORD dwErr = 0;
debug_log("In Service Main-The Entry Point for Service");

// Register the handler function to service
svcStatusHandle = RegisterServiceCtrlHandlerEx(TEXT(SRVCNAME),(LPHANDLER_FUNCTION_EX)SvcCtrlHandler,NULL);
if(!svcStatusHandle)
{
debug_log("Failed to register service handler function error(%d) returned",GetLastError());
(VOID)ReportServiceStatus(SERVICE_STOPPED,dwErr,0);
return;
}
// service status members remain same as set here.
svcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
svcStatus.dwServiceSpecificExitCode = 0;

if(!ReportServiceStatus( SERVICE_START_PENDING, NO_ERROR, 3000 ));
CleanupHandles();

//Start the service...
ServiceStart(dwArgs,lpszArgv);
debug_log("Exiting Service Main");
}


//Function for installing the service in SCM database

BOOL InstallService(char *szPath)
{
SC_LOCK sclLock;
LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf;
SERVICE_DESCRIPTION sdBuf;
DWORD dwBytesNeeded;
BOOL bSuccess=TRUE;
SC_ACTION sca[3];
SERVICE_FAILURE_ACTIONS sfaBuf;

debug_log("Installing service now...");
//Get a handle to SCM database..
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE | SC_MANAGER_ALL_ACCESS | SC_MANAGER_LOCK | SC_MANAGER_QUERY_LOCK_STATUS);

if (schSCManager == NULL)
{
debug_log("Failed to open SCM database, error-(%d) returned\n",GetLastError());
return false;
}
else debug_log("Connection to SCM database success");

LPCTSTR lpszBinaryPathName= szPath;
// If database opened create the service
schService = CreateService(schSCManager,SRVCNAME,SRVCNAME,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,lpszBinaryPathName,NULL,NULL,NULL,NULL,"");

if(schService == NULL)
{
debug_log("Error in creating service,[%d] error code returned",GetLastError());
return false;
}
else debug_log("Service %s created and installed",SRVCNAME);

CloseHandle(schService);

// service config change to specify action on failure
debug_log("Acquiring lock on SCM database");
sclLock = LockServiceDatabase(schSCManager);

if (sclLock == NULL)
{
if (GetLastError() != ERROR_SERVICE_DATABASE_LOCKED)
{
debug_log("Database Lock failed");
return FALSE;
}

// Allocate buffer to det details about the lock
lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS)LocalAlloc(LPTR,sizeof(QUERY_SERVICE_LOCK_STATUS)+ 256);
if (lpqslsBuf == NULL)
{
debug_log("Local alloc failed");
return FALSE;
}

// Get the lock status information
if(!QueryServiceLockStatus(schSCManager,lpqslsBuf,sizeof(QUERY_SERVICE_LOCK_STATUS)+256,&dwBytesNeeded))
{
debug_log("Query lock status failed");
return FALSE;
}
if (lpqslsBuf->fIsLocked)
{
debug_log("Already locked by %s",lpqslsBuf->fIsLocked);
}
else
LocalFree(lpqslsBuf);
}

//if database is locked make the changes
schService= OpenService(schSCManager,SRVCNAME,SERVICE_ALL_ACCESS | SERVICE_CHANGE_CONFIG);
if (schService == NULL)
{
debug_log("Open service failed");
return FALSE;
}
sca[0].Type = SC_ACTION_RESTART;
sca[0].Delay = 1;
sca[1].Type = SC_ACTION_RESTART;
sca[1].Delay = 1;
sca[2].Type = SC_ACTION_RESTART;
sca[2].Delay = 1;
sfaBuf.cActions = 3;
sfaBuf.lpsaActions = sca;
sfaBuf.dwResetPeriod = INFINITE;
sdBuf.lpDescription = "Test Service";

if (!ChangeServiceConfig2(schService,SERVICE_CONFIG_FAILURE_ACTIONS,&sfaBuf))
{
debug_log("Change service config failed");
bSuccess = FALSE;
}
UnlockServiceDatabase(sclLock);
CleanupHandles();

debug_log("Exiting install service...");
return bSuccess;
}





// Start the service

VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv)
{
debug_log("Inside Service Start,Service Started");
SERVICE_STATUS_PROCESS ssStatus;
DWORD dwOldCheckPoint;
DWORD dwStartTickCount;
DWORD dwWaitTime;
DWORD dwBytesNeeded;


// Acquire handle to the SCM database.
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);

if (schSCManager == NULL)
{
debug_log("OpenSCManager failed (%d)\n", GetLastError());
return;
}


// Handle to the service.
schService = OpenService(schSCManager,SRVCNAME,SERVICE_ALL_ACCESS);

if (schService == NULL)
{
debug_log("OpenService failed (%d)\n", GetLastError());
CloseServiceHandle(schSCManager);
return;
}

// Start the service.
if (!StartService(schService,0,NULL) )
{
debug_log("StartService failed error-(%d) returned\n", GetLastError());
CleanupHandles();
return;
}

// Check if the service has started
if (!QueryServiceStatusEx(schService,SC_STATUS_PROCESS_INFO,(LPBYTE) &ssStatus,sizeof(SERVICE_STATUS_PROCESS),
&dwBytesNeeded ) )
{
debug_log("Service status 1 query failed,error[%d] returned",GetLastError());
return;
}


// Check the system start time....
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ssStatus.dwCheckPoint;

while (ssStatus.dwCurrentState == SERVICE_START_PENDING)
{
dwWaitTime = ssStatus.dwWaitHint / 10;
if( dwWaitTime < 1000 )
dwWaitTime = 1000;
else if ( dwWaitTime > 10000 )
dwWaitTime = 10000;

Sleep( dwWaitTime );

// Check the status again.
if (!QueryServiceStatusEx(schService,SC_STATUS_PROCESS_INFO,(LPBYTE) &ssStatus,sizeof(SERVICE_STATUS_PROCESS),
&dwBytesNeeded ) )
{
debug_log("Service status 2 query failed,error[%d] returned",GetLastError());
break;
}

if ( ssStatus.dwCheckPoint > dwOldCheckPoint )
{
// Service is running with system start
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ssStatus.dwCheckPoint;
}
else
{
if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint)
{
//Service hasn't been started with system start
debug_log("Service has not started with system startup");
break;
}
}
}

// Determine whether the service is running
if (ssStatus.dwCurrentState == SERVICE_RUNNING)
{
debug_log("Service has been started successfully.\n");
}
else
{
debug_log("Service not started. \n");
debug_log(" Current State: %d\n", ssStatus.dwCurrentState);
debug_log(" Exit Code: %d\n", ssStatus.dwWin32ExitCode);
debug_log(" Check Point: %d\n", ssStatus.dwCheckPoint);
debug_log(" Wait Hint: %d\n", ssStatus.dwWaitHint);
}
// Start the action to be performed by the service..
debug_log("Starting the service init process now,work to be performed by service");
ServiceInit();
debug_log("Exiting Service Start now..");
CleanupHandles();

}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////******

all the variables used have been declared and there are no compilation error...
using visual studio 2008 for service application development for windows vista...


Thankuou...
AnswerRe: error in starting widows service after installation Pin
Cedric Moonen30-Jun-09 0:58
Cedric Moonen30-Jun-09 0:58 
GeneralRe: error in starting widows service after installation Pin
Chuck O'Toole30-Jun-09 22:57
Chuck O'Toole30-Jun-09 22:57 
GeneralRe: error in starting widows service after installation Pin
Subrat Patnaik1-Jul-09 0:54
Subrat Patnaik1-Jul-09 0:54 
GeneralRe: error in starting widows service after installation Pin
Cedric Moonen1-Jul-09 0:56
Cedric Moonen1-Jul-09 0:56 
QuestionDoubt in MapMode Pin
KASR129-Jun-09 23:34
KASR129-Jun-09 23:34 
AnswerRe: Doubt in MapMode Pin
led mike30-Jun-09 4:34
led mike30-Jun-09 4:34 
Questionwmi problem Pin
Mogaambo29-Jun-09 23:03
Mogaambo29-Jun-09 23:03 
QuestionIOCTL codes Pin
AnayKulkarni29-Jun-09 21:07
AnayKulkarni29-Jun-09 21:07 
AnswerRe: IOCTL codes Pin
Cedric Moonen29-Jun-09 22:21
Cedric Moonen29-Jun-09 22:21 
AnswerRe: IOCTL codes Pin
Roger Stoltz30-Jun-09 1:25
Roger Stoltz30-Jun-09 1:25 
QuestionCMYK values Pin
S p k 52129-Jun-09 20:56
S p k 52129-Jun-09 20:56 
AnswerRe: CMYK values Pin
Nuri Ismail29-Jun-09 21:19
Nuri Ismail29-Jun-09 21:19 
GeneralRe: CMYK values Pin
S p k 52129-Jun-09 21:57
S p k 52129-Jun-09 21:57 
GeneralRe: CMYK values Pin
Nuri Ismail29-Jun-09 22:04
Nuri Ismail29-Jun-09 22:04 
AnswerRe: CMYK values Pin
Chris Losinger30-Jun-09 10:24
professionalChris Losinger30-Jun-09 10:24 
GeneralRe: CMYK values Pin
Nuri Ismail30-Jun-09 20:42
Nuri Ismail30-Jun-09 20:42 
AnswerRe: CMYK values Pin
Alan Balkany1-Jul-09 4:14
Alan Balkany1-Jul-09 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.