Click to See Complete Forum and Search --> : Service Program
joscollin
November 6th, 2003, 12:55 AM
Hi ,
My Service program's StartServiceCtrlDispatcher() fails and the error code is 1063. (ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
What's the reason?
I'm logged in as Administrator in win2K.
The following is the main function.
thanks,
collin
void main()
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{"MyService", NTServiceMain},
{NULL, NULL}
};
if (StartServiceCtrlDispatcher( DispatchTable))
{
printf("\nservice dispatcher started");
}
else
{
char buf[10];
DWORD err = GetLastError();
sprintf(buf, "%u", err);
printf("%s", buf);
}
}
vicodin451
November 6th, 2003, 06:17 AM
Is your service installed (CreateService)?
joscollin
November 6th, 2003, 11:36 PM
Originally posted by vicodin451
Is your service installed (CreateService)?
The Service is Installed successfully.
But the problem is with StartServiceCtrlDispatcher()
and StartService().
There are api's for installing and starting a service.
Could u please tell me the order for using these functions and also where to use the StartServiceCtrlDispatcher() ,ServiceMain(), ServiceHandler and ServiceInitialization functions
vicodin451
November 7th, 2003, 08:01 AM
Did you see this note in the doc for StartServiceCtrlDispatcher:
Return Values
ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
Typically, this error indicates that the program is being run as a console application rather than as a service.
If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.
How are you starting the service - from the debugger, or with the Services management console (or net start "servicename")?
vicodin451
November 7th, 2003, 08:06 AM
Check out "Creating a Simple Win32 Service in C++" in the "DLLs, Processes, and Threads Technical Articles" section of MSDN.
The article discusses services, and a C++ class that makes writing services easier. It is important, though, to understand what the class is doing so take the time to review the article and the provided code...
joscollin
November 8th, 2003, 04:45 AM
Originally posted by vicodin451
Did you see this note in the doc for StartServiceCtrlDispatcher:
How are you starting the service - from the debugger, or with the Services management console (or net start "servicename")?
The StartService error is
Could not start the service on local computer
Error 1053: The service did not respond to the start or control request in a timely fashion.
I know this is request time out, but I cannot find the problem.
pls reply...
vicodin451
November 8th, 2003, 10:52 PM
Originally posted by vicodin451
How are you starting the service - from the debugger, or with the Services management console (or net start "servicename")?
joscollin
November 9th, 2003, 09:07 AM
I am starting the service using a console based application(code attached).
I run it from console by giving service name as command line argument.
vicodin451
November 9th, 2003, 11:20 AM
I run it from console by giving service name as command line argument.
Did you see my post regarding the MSDN comment about the error you get:
Return Values
ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
Typically, this error indicates that the program is being run as a console application rather than as a service.
Start your services via the Services management console (services.msc).
joscollin
November 9th, 2003, 11:24 PM
Originally posted by vicodin451
Did you see my post regarding the MSDN comment about the error you get:
Start your services via the Services management console (services.msc).
I Installed the service by InstallService call
and start it from Services management console.
This too gives error code: 1053.
vicodin451
November 10th, 2003, 07:11 AM
Did you check out the "Creating a Simple Win32 Service in C++" article in MSDN, and try some of the ideas presented there?
vicodin451
November 10th, 2003, 09:15 AM
Ummm....
Here's your problem - you are killing the service right away, since the command line for the service when invoked by the Services management console / net start ServiceName does not match your requirement:
if (!(argc == 3 || argc == 4))
{
printf("usage: instsrv <service name> <command> [exe location]\n");
exit(1);
}
Remove this, and the service will toss out an AV, probably because of the following similar code:
if(!strcmp(argv[2], "remove"))
RemoveService(argv[1]);
else if(!strcmp(argv[2], "run"))
RunService(argv[1], 0, NULL);
else if(!strcmp(argv[2], "stop"))
StopService(argv[1]);
else if(!strcmp(argv[2], "install"))
InstallService(argv[1], argv[3]);
These args (argv[2], etc) don't exist. You're accessing memory you shouldn't be.
When you fix these, you'll still get 1053, but that's because you're not setting the service status properly, etc. That's where the MSDN article comes in handy. I really encourage you to check it out.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.