473,574 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prevent a service from stopping.

How do I programmaticall y prevent a service from stopping? I want to
be able to keep my service running (started), under certain conditions,
when a user tries to stop it. I have tried throwing an exception

- from OnStop(): the SCM waits for a long time, reports that the
service didn't respond in a timely fashion and then leaves the status
as stopping.
- from Dispose(): the SCM displays an error dialog with the exception
details and prompts me to select a debugger. If I select 'No' the
service is stopped.

..NET Framework 1.1
MSDE 2003
Windows 2000 SP4

Jan 13 '06 #1
5 17403
Set the 'CanStop' property of the service to false.

-mdb

ch***********@t eleware.co.uk wrote in news:1137170528 .586382.30670
@g47g2000cwa.go oglegroups.com:
How do I programmaticall y prevent a service from stopping? I want to
be able to keep my service running (started), under certain conditions,
when a user tries to stop it. I have tried throwing an exception

Jan 13 '06 #2
Michael Bray <mbray@makeDInt oDot_ctiusaDcom > wrote in
news:Xn******** *************** ****@207.46.248 .16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceControll er class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb
Jan 13 '06 #3
Just s quick note - you wouldn't need remoting for controlling the service,
a ServiceControll er's ExecuteCommand method would suffice if you need just a
parameterless command not returning anything

"Michael Bray" <mbray@makeDInt oDot_ctiusaDcom > wrote in message
news:Xn******** *************** *****@207.46.24 8.16...
Michael Bray <mbray@makeDInt oDot_ctiusaDcom > wrote in
news:Xn******** *************** ****@207.46.248 .16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceControll er class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb

Jan 13 '06 #4
"Lebesgue" <no****@spam.jp > wrote in
news:O#******** *****@TK2MSFTNG P09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceControll er's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb
Jan 13 '06 #5
You will have to specify "the specific error" This can be caused by numerous
reasons, insufficient privileges to control the service would be the first
thing to look at.

"Michael Bray" <mbray@makeDInt oDot_ctiusaDcom > wrote in message
news:Xn******** *************** ****@207.46.248 .16...
"Lebesgue" <no****@spam.jp > wrote in
news:O#******** *****@TK2MSFTNG P09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceControll er's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb

Jan 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2592
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart event.... objEventLog.EnableRaisingEvents = Tru ....It starts fin I have the same issue when stopping the service because of below line of code in...
4
15874
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group : microsoft.public.dotnet.languages.csharp URL :...
7
3853
by: Steve Long | last post by:
In writing a Windows service with .NET, I'm noticing that the process for some services can not be killed with specifically stopping the service. If you try to kill the process with, say task manager, you get an access denied message. I just wrote a test service and I can kill the process for this service without actually stopping the service....
9
7246
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
23
7564
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception...
2
2249
by: matteo | last post by:
Hi everyboby, i wrote a c# service that every XXX minute launch a working thread on timer events, something like this: private void timer_Elapsed ( object status ) { // Worker thread System.Threading.ThreadPool.QueueUserWorkItem ( new System.Threading.WaitCallback( _timer_Elapsed ) );
6
8045
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class functions __init__, SvcStop, and SvcDoRun (which contains my server code). After registering the service, I am able to start it with no problems....
5
6477
by: marccruz | last post by:
Hi, I am writing a Windows Service in C#. I want to gracefully fail the "protected override void OnStop()" function. To do this, I first tried throwing an Exception in the function. However, that left the Service in a "Stopping" state. I would like to fail the Service in the OnStop function without putting the service in the Stopping...
0
2186
by: mattcfisher | last post by:
Hi, I have two windows services running together. One is the main program, and one is an "updater" wrapper for the main. The updater service starts and stops the main one (as in you should never start or stop main service manually, only updater). On most computers it works great, the updater's onStop() can start and stop the main service...
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8053
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7817
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3752
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2245
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.