Solved

Stopping other services after receiving STOP_SERVICE signal

Posted on 1998-12-19
10
178 Views
Last Modified: 2010-04-15
I am writing a service.
When my service receives SERVICE_STOP or SERVICE_SHUTDOWN
signal, it is notifying the SCM that it is stopping,
and starts the stopping procedure.

In the stopping procedure,
it should stop another service. For example (c code):

system("net stop wins");

but when I do that, it does not work.
Any other command line would work, but stopping a service
just gets stuck.

Where have I gone wrong ?
Is there a special way to stop a service from inside service stopping procedure ?

Sorry I can't give more points.
That's all I got left.
0
Comment
Question by:kramero
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1255336
You can use the ControlService() API with the SERVICE_CONTROL_STOP control to stop the service (if you got the privilage).

By the way, this is not a "C" question.   You should have asked it in the "Windows" programming area.
0
 

Author Comment

by:kramero
ID: 1255337
Hi alexo.
I am familiar with this API call.

What I am looking for is an explanation for the fact that
a script running NET STOP <service name> gets stuck.

0
 
LVL 86

Expert Comment

by:jkr
ID: 1255338
The problem why your script gets stuck is that a service doesn't have the rights to access (and therefore execute) a script - this is a common problem with services that aren't assigned to run under a certain account. Two ways to overcome this: Assign your service to account manually (using the control panel) or use 'LogonUser()' and 'ImpersonateLoggedOnUser()' to accomplish this...
0
Industry Leaders: 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!

 

Author Comment

by:kramero
ID: 1255339
Hy JKR!
My service secceeds to run the script.
Everything in the script is OK until the NET STOP <...>.
If I take off the NET STOP command everything runs fine.
So I guess access is not the problem.
Maybe it has something to do with the SCM.
0
 

Author Comment

by:kramero
ID: 1255340
Adjusted points to 85
0
 
LVL 86

Expert Comment

by:jkr
ID: 1255341
Well, i still think that it is a privilege problem (e.g. insufficiant rights for a service to execute 'net.exe'). Try to assign the service to a user account, and then let's see ;-)
0
 
LVL 11

Expert Comment

by:alexo
ID: 1255342
>> Try to assign the service to a user account
Also make sure that the account has the "run as service" privilege.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1255343
>>Also make sure that the account has the "run as service"
>>privilege.
alexo, you're right of course ;-)

0
 

Author Comment

by:kramero
ID: 1255344
Well,
Assigning the service to a user account with "run as service"
didn't work.
Using ServiceControl (Openning SCM etc...)
didn't work too.

It looks like from inside a stopping procedure of a service,
you can not ask to stop other services.
I don't know why!
and I can't find any documentation.

By the way -
Dependent Services wont help me in this case,
Don't ask me why. It's too long to explain...

I just need to find out how to stop a service from a stopping service...
0
 
LVL 2

Accepted Solution

by:
abesoft earned 200 total points
ID: 1255345
The problem is in the service control manager, which is the process that called into your service with a SHUTDOWN message.  It is only able to handle one transaction at a time, and it is currently calling you.  If you try to ask it to shut down another service (which is what your system(...) call does in the end) then it won't be able to.

Try returning from the request, and then doing the system() call.  You may need to have an external routine to do the actual work (I have no idea what architecture you're using.)
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

688 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