Re: Restart Window Service
- From: cleohm <cleohm@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 2 Mar 2008 20:34:01 -0800
Hi,
I am running the following code on WinXP Prof. Personally, I feel that this
is a handler out of scope issue but do not know how I can go about resolving
this. Do help shed some light if possible. Thanks.
service_main(){
serviceStatus.dwServiceType = SERVICE_WIN32;
serviceStatus.dwCurrentState = SERVICE_START_PENDING;
serviceStatus.dwControlsAccepted = 0;
serviceStatus.dwWin32ExitCode = NO_ERROR;
serviceStatus.dwServiceSpecificExitCode = NO_ERROR;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 3000;
hServiceStatusHandle = RegisterServiceCtrlHandler(pServiceName,
XYNTServiceHandler);
if (hServiceStatusHandle==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "RegisterServiceCtrlHandler failed, error code = %d",
nError);
AfxMessageBox(pTemp);
return;
}
SetServiceStatus(hServiceStatusHandle, &serviceStatus);
}
VOID WINAPI ServiceHandler(DWORD fdwControl)
{
switch(fdwControl)
{
case SERVICE_CONTROL_STOP:
serviceStatus.dwCurrentState =
SERVICE_STOPPED;
serviceStatus.dwCheckPoint
= 0;
serviceStatus.dwWaitHint = 1000;
SetServiceStatus(hServiceStatusHandle, &serviceStatus));
serviceStatus.dwCurrentState =
SERVICE_RUNNING;
SetServiceStatus(hServiceStatusHandle, &serviceStatus);
break;
}
}
Regards
cleohm
"Joseph M. Newcomer" wrote:
Which version of Windows? What does the code look like? What ACLs were set for the.
service? What service?
Otherwise, the answer is "you are doing something either incorrectly, or forbidden. Either
fix the bug, or don't do that"
hie
On Sun, 2 Mar 2008 00:34:01 -0800, cleohm <cleohm@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi,Joseph M. Newcomer [MVP]
I have an application that attempts to start a service that is detected to
be stopped by the user using SetServiceStatus. However, this is only
successful on the first time but fails on the subsequent tries with an error
message 'Could not stop the <service name> service on local computer. The
service did not return an error. This could be an internal windows error or
an internal service error. if problem persists, contact your system
administrator'. Anyone knows why?
Regards
cleohm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Follow-Ups:
- Re: Restart Window Service
- From: Joseph M . Newcomer
- Re: Restart Window Service
- References:
- Re: Restart Window Service
- From: Joseph M . Newcomer
- Re: Restart Window Service
- Prev by Date: Re: Multiprocessor crash.
- Next by Date: Re: Restart Window Service
- Previous by thread: Re: Restart Window Service
- Next by thread: Re: Restart Window Service
- Index(es):