Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Starting service failed

Posted on 2003-12-10
6
Medium Priority
?
655 Views
Last Modified: 2013-12-03
I am writing a service using the helper classes from the book "Programming Server-Size Applications for Microsoft Windows 2000" by Jeffrey Richter, Jason D. Clark. Starting the service in TimeServer book sample looks like this:

         case SERVICE_CONTROL_CONTINUE:
            hpipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\TimeService"),
               PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
               PIPE_TYPE_BYTE, 1, sizeof(st), sizeof(st), 1000, NULL);

            iocp.AssociateDevice(hpipe, CK_PIPE);
            ZeroMemory(&o, sizeof(o));
            ConnectNamedPipe(hpipe, &o);
            g_ssTime.ReportUltimateState();
            break;

Since this is just a sample, there is no error handling and service start is supposed to succeed always. Appropriate code fragment from my program:

            case SERVICE_CONTROL_CONTINUE:
                if ( g_ServerSocket.Start(PORT_NUMBER) )
                {
                    // success
                    g_ssScan.ReportUltimateState();
                    g_EventLog.ReportEvent(EVENTLOG_INFORMATION_TYPE, CAT_APPEXECSTATUS, MSG_APPSTART);
                }
                else
                {
                    // failed
                    // What to do here ???
                }
                break;

I want to report error to SCM. Currently it tries to start my service a lot of time, I cannot say "Operation failed". Service remains in the state "Starting".
0
Comment
Question by:AlexFM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9912601
>>// What to do here ???

I don't know what 'ReportUltimateState()' does or whether there are other reporting functions, but the usual 'way of conduct' would be to set the service ststus to what is appropriate - that is 'SERVICE_STOPPED' if *starting* it failed - however, as the above code is about 'SERVICE_CONTROL_CONTINUE', which indicates resuming a paused service, 'SERVICE_PAUSED' might be appropriate.

0
 
LVL 11

Expert Comment

by:KurtVon
ID: 9912637
0
 
LVL 48

Author Comment

by:AlexFM
ID: 9912697
Thanks. Meanwhile I found some workaround:

                if ( g_ServerSocket.Start(PORT_NUMBER) )
                {
                    // CServiceStatus::ReportUltimateState changes current service status
                    // and calls SetServiceStatus API
                    g_ssScan.ReportUltimateState();
                    g_EventLog.ReportEvent(EVENTLOG_INFORMATION_TYPE, CAT_APPEXECSTATUS, MSG_APPSTART);
                }
                else
                {    
                    g_ssScan.SetUltimateState(SERVICE_STOPPED, 2000);
                    iocp.PostStatus(CK_SERVICECONTROL, SERVICE_CONTROL_STOP);
                }

As result of this, service reports Start and immidiately after this Stop. SCM is not so happy, but service state becomes Stopped. I hope there is a best solution.
Maybe somebody who worked service template from "Service Programming" book can help.
This code is in ServiceMain and not in HandlerEx function. HandlerEx already returned NO_ERROR. Maybe it is too late to report unsuccessful start and my workaround is the only solution?
0
 
LVL 86

Expert Comment

by:jkr
ID: 9912902
>>SCM is not so happy, but service state becomes Stopped. I hope there is a best solution.

Well, that *is* the solution, as the service status hardly can be anything else if the startup failed...
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 9978980
I see no reason for a deletion.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question