Solved

NT Service

Posted on 2002-04-29
17
254 Views
Last Modified: 2011-09-20
I get the following error while trying to stop a service from control panel/services applet in Windows NT-4.0 environment. I have not used MFC.

"Error 0109: The pipe has been ended". I do not see any errors in EventLog and everything else seems to be fine.

What's going on? Can someone help?

Thanks!
0
Comment
Question by:arvind_cs
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
This usually happens when a service does not report the "stopped" state to the SCM by calling

SERVICE_STATUS          ssStatus;       // current status of the service
SERVICE_STATUS_HANDLE   sshStatusHandle;

ssStatus.dwCurrentState = SERVICE_STOPPED;
ssStatus.dwWin32ExitCode = 0;
ssStatus.dwWaitHint = 0;
ssStatus.dwCheckPoint = 0;
SetServiceStatus( sshStatusHandle, &ssStatus);
0
 

Author Comment

by:arvind_cs
Comment Utility
No, that code exists! I get the error despite that.
0
 

Author Comment

by:arvind_cs
Comment Utility
No, that code exists! I get the error despite that.
0
 
LVL 3

Expert Comment

by:job_s
Comment Utility
Is there any message box or blocking code is there?
0
 

Author Comment

by:arvind_cs
Comment Utility
No message box. This is a NT service, there can be no message boxes even if I wanted to display one. NT Services, by definition, cannot have user interfaces.
0
 
LVL 3

Expert Comment

by:job_s
Comment Utility
U can use dialogs or messageboxes by specifying

SERVICE_INTERACTIVE_PROCESS with

SERVICE_WIN32_OWN_PROCESS  or SERVICE_WIN32_SHARE_PROCESS


0
 
LVL 3

Expert Comment

by:job_s
Comment Utility
if this flag is not specified SERVICE_INTERACTIVE_PROCESS

MessageBox or dialog creation will create error
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
This is OT, but 'MessageBox()' with MB_SERVICE_NOTIFICATION would do it also :o)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:Wildfire
Comment Utility
It sounds like it may not be a Service problem but rather a problem with the access of a thread from a pipe after it has been closed.

Resolution:
 1)Check that all network operations e.g. File, Database etc Access has stopped before terminating your service thread (SERVICE_STOP).
 2)Confirm that you are not experiencing a hardware issue.  
Question:
 1)What external resource are you trying to access?
0
 

Author Comment

by:arvind_cs
Comment Utility
job_s and jkr: this service would run from an unattended NT Server so displaying message box is not an option - it is a kludgy way to do things anyway (who'd be there to click on OK buttons on message boxes?). Besides, what's the point? How are message boxes related to my problem? :-)

Wildfire: you are on the button...my service is multithreaded so it is definitely a pipe issue. I have taken care to close all resources and I terminate threads on event by WaitForMultipleObjects.




0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>job_s and jkr

You misreaad my comment - it said 'OT' :o)
0
 

Author Comment

by:arvind_cs
Comment Utility
jkr: OT?! = On Target? or = Over the Top? or = OhwhatTheheck?  :-)

...just kidding..:-)

0
 

Author Comment

by:arvind_cs
Comment Utility
It is extremely hard to debug a service. Any ideas apart from inerting timestamps into a log-file at suspect points in code?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
OT = off topic :o)

To get back to to your problem - set the service to "interact with the desktop" and issue a "DebugBreak()" from your code at a point of interest. That should start the debugger on *your* desktop.
0
 
LVL 1

Accepted Solution

by:
Wildfire earned 100 total points
Comment Utility
The best way to debug a service is to attach to the Visual C++ debugger while the service is running. To do this, start the service, obtain the process identifier, and then connect the debugger to the running process.

To find the process identifier use the program PVIEW.EXE from the Windows NT Resource Kit.
Caution This utility is not identical with the utility of the same name distributed with Microsoft Visual C++ and the Platform SDK. It is an extended version with more functionality. The correct version displays the window title Process Explode, rather than Process Viewer.

Start the service to be debugged. The service must be running before you can find its process identifier.

Start a command prompt or open an existing command prompt. Be sure that it is the only command prompt currently active.

Start PVIEW and in the drop-down list box near the top left of the PVIEW screen, find and select the process IDENTIFIER corresponding to CMD.EXE.

In the PVIEW dialog box, select Token. Click Process.

In Privileges, move SetDebugPrivilege from the Disabled box to the Enabled box. Click OK.

Connect Visual C++ to the running service. Note that when you use the process identifier from the Windows NT Server version of PVIEW.EXE, the process identifier is in decimal not hexadecimal. Start Visual C++ with the command line: START MSDEV /P nnn where nnn is the process identifier in decimal or hexadecimal notation.

This is a very well documented way of debugging an 'in process' application.  See MSDN for further details.  I do NOT recommend trying to insert dialog boxes everywhere just to see if it runs through.  I personally would like to step through a service I'm trying to debug.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>The best way to debug a service is to attach to the
>>Visual C++ debugger while the service is running.
>>To do this, start the service, obtain the process
>>identifier, and then connect the debugger to the running
>>process.

That'sm mainly what I explained above. Witth the subtle difference that you have to allow the service to "run" on the user's desktop, otherwise VS will show up on the "invisible" service's desktop, which is not really helpful...
0
 

Author Comment

by:arvind_cs
Comment Utility
Thanks for answering in detail. I agree with you that messageboxes are not the way to go in services. A message-box blocks execution for that thread until it is dismissed so I would not be able to replicate the 'natural' sequence of events. Logging into eventlog is a better approach but unfortunately I cannot get precision details about the exact timing upto millisecond in the eventlog. I feel that my 'pipe-ended' problem is primarily a timing issue with respect to how and when exactly I inform the scum that I'm quitting the service.

I am not sure if I would be able to debug much using this technique since I would not be able to dig into the scum anyway but I will give you the points as you described an approach that could lead me on to finding more clues.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now