PC Review


Reply
Thread Tools Rate Thread

How do you stop a Window Service

 
 
srcleveland@micron.com
Guest
Posts: n/a
 
      23rd Feb 2007
I am trying to have a windows service stop itself. I am currently
using the following code but I would like to find a way to stop the
service without having to shell out to a command prompt

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = " /C sc stop \"" + this.serviceDisplayName +
"\"";
p.Start();
p.WaitForExit();

One of the drawbacks of the above code is that you have to know the
name under which the service is running in order to be able to stop it.

 
Reply With Quote
 
 
 
 
Mike Labosh
Guest
Posts: n/a
 
      24th Feb 2007
> I am trying to have a windows service stop itself. I am currently
> using the following code but I would like to find a way to stop the
> service without having to shell out to a command prompt


If it needs to stop itself, can't you just have this service call it's own
overridden Stop() method?
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei


 
Reply With Quote
 
PS
Guest
Posts: n/a
 
      24th Feb 2007

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to have a windows service stop itself. I am currently
> using the following code but I would like to find a way to stop the
> service without having to shell out to a command prompt
>
> Process p = new Process();
> p.StartInfo.FileName = "cmd.exe";
> p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
> p.StartInfo.Arguments = " /C sc stop \"" + this.serviceDisplayName +
> "\"";
> p.Start();
> p.WaitForExit();
>
> One of the drawbacks of the above code is that you have to know the
> name under which the service is running in order to be able to stop it.


So you are wanting to stop the name of a service when you don't know it's
name, is that correct?

You can use the ServiceController class however you will still need to know
the name of the service.

PS


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable automatic stop on window service? Lemune Microsoft C# .NET 8 8th Jun 2009 11:23 AM
Why wont my Service stop..Failed to stop service.Appreciate advices shakthi Microsoft C# .NET 2 30th Oct 2008 09:33 PM
.NET Runtime Optimization Service causing Web Service to stop responding?? Bloody Hell Microsoft Dot NET Framework 0 22nd Sep 2006 03:48 PM
How can I remotely stop Windows service, do some stuff, and start the remove service again. anonieko@hotmail.com Windows XP Help 0 28th Oct 2005 12:35 AM
how do I stop Outlook 2003 service pack 1 from crashing in Window. =?Utf-8?B?d2ViZG9nZw==?= Microsoft Outlook Discussion 1 30th Dec 2004 12:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.