473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do you stop a Window Service

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.

Feb 23 '07 #1
2 1560
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
Feb 23 '07 #2
PS

<sr*********@micron.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
>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
Feb 24 '07 #3

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

Similar topics

1
by: José Joye | last post by:
Hi, For some reason, I have a VB6 appl (that expose no forms) that I mustcontrol using a C# service. I'm able to start it from my service using the Process class. However, I do not really...
1
by: Mike001 | last post by:
Hi I have developed a Windows service in C# (inherited from System.ServiceProcess.ServiceBase) and, after the service has successfully started, when I catch an exception I'd like to write the code...
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
0
by: archana | last post by:
Hi all, I am having web service which is deployed on windows server 2003. I am using that web service in my windows application. That window service is inserting large amount of data from...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
3
by: Goran Djuranovic | last post by:
Hi all, I have a web app running on a local PC that can start and stop windows service on a remote machine, but only when I browse to it locally. If I browse to it from my other PC and try to...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
2
by: KarthikeyanS08 | last post by:
I need to stop a windows service...And can anyone tell if i can stop a CRM web server and web service running as a window service using the same code.Thanks.
8
by: Lemune | last post by:
Hi, I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.