Windows Service Stop

  • Thread starter Thread starter NM
  • Start date Start date
N

NM

Hi,

I'd like to know if it is possible to stop (within the code) a windows
service just after a business exception has been thrown...

TIA.

NM
 
Hi,

You are not telling us what language you are using, so i will just give you
a general solution:

net stop <serviceNameHere>

For more information, write: "net stop /?" in a cmd prompt. You can probably
use this from your code in one or another way.

--
Regards,
Kristofer Gafvert
http://www.ilopia.com - My personal Web Site, with information about things
i find interesting, for example Windows Server 2003.
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.
 
Hi,

This is one way to do it:

--- Code snippet ---

System.ServiceProcess.ServiceController sc = new
System.ServiceProcess.ServiceController("my Service Name");
sc.Stop();

--- End Code Snippet ---

I do not know if there's another way to do it, so i suggest that you ask in
public.dotnet.languages.csharp if you do not think this is the best
solution.

For more information, please look at the ServiceController class in MSDN

Hope this helps!

--
Regards,
Kristofer Gafvert
http://www.ilopia.com - My personal Web Site, with information about things
i find interesting, for example Windows Server 2003.
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top