474,077 Members | 5,622 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 17627
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
2646
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 my OnStop even
4
15920
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
3883
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. Can someone tell me how to keep the process for my service from being killed without actually...
9
7288
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
7657
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 thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
2
2268
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
8201
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. However, it never stops correctly (net stop returns "service could not be stopped") and service is left...
5
6518
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 state. It would be nice if it's still in the Started state. Is this possible? If so, how?
0
2214
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 perfectly. On some computers, though, the updater hangs when it tries to stop the main service. It...
0
10427
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11682
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
11202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7953
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
6760
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6945
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5505
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
3
4060
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.