?
Solved

NT Service

Posted on 2002-04-29
17
Medium Priority
?
263 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
[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
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6977910
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
ID: 6978096
No, that code exists! I get the error despite that.
0
 

Author Comment

by:arvind_cs
ID: 6978108
No, that code exists! I get the error despite that.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:job_s
ID: 6979514
Is there any message box or blocking code is there?
0
 

Author Comment

by:arvind_cs
ID: 6980578
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
ID: 6980586
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
ID: 6980591
if this flag is not specified SERVICE_INTERACTIVE_PROCESS

MessageBox or dialog creation will create error
0
 
LVL 86

Expert Comment

by:jkr
ID: 6980669
This is OT, but 'MessageBox()' with MB_SERVICE_NOTIFICATION would do it also :o)
0
 
LVL 1

Expert Comment

by:Wildfire
ID: 6980677
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
ID: 6981106
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
ID: 6981131
>>job_s and jkr

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

Author Comment

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

...just kidding..:-)

0
 

Author Comment

by:arvind_cs
ID: 6981422
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
ID: 6982486
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 300 total points
ID: 6983947
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
ID: 6983961
>>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
ID: 6999191
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

770 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