473,386 Members | 1,817 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,386 software developers and data experts.

Checking Existing Windows Service

Hi, All!

I just would like to ask... Is it possible that you can detect whether a
Windows Service is existing or not? If this is possible, how can you
implement it?

Thank you!

A
Nov 16 '05 #1
3 1311
Ann,

The easiest way would be to use the classes in the System.Management
namespace to perform a WMI query for the instance of Win32_Service that
corresponds to the service you are looking for. This will let you determine
whether the service exists, is it running, etc, etc.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ann Marinas" <ma*******@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi, All!

I just would like to ask... Is it possible that you can detect whether a
Windows Service is existing or not? If this is possible, how can you
implement it?

Thank you!

A

Nov 16 '05 #2
Thank you so much. I really do appreciate the help!

I'll try to apply this on my application.

Thank you!

Ann

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2***************@tk2msftngp13.phx.gbl...
Ann,

The easiest way would be to use the classes in the System.Management
namespace to perform a WMI query for the instance of Win32_Service that
corresponds to the service you are looking for. This will let you determine whether the service exists, is it running, etc, etc.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ann Marinas" <ma*******@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi, All!

I just would like to ask... Is it possible that you can detect whether a
Windows Service is existing or not? If this is possible, how can you
implement it?

Thank you!

A


Nov 16 '05 #3
If you don't want to work through the WMI query syntax, this may be a little
easier:
//required for using ServiceController
using System.ServiceProcess;

private bool ServiceExists(string serviceName)
{
ServiceController[] allServices = ServiceController.GetServices();
bool result = false;
ServiceController sc = null;
for (int i = 0; i < allServices.Length; i++)
{
if (allServices[i].ServiceName.ToLower() == serviceName.ToLower())
{
result = true;
break;
}
}
return result;
}

"Ann Marinas" <ma*******@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi, All!

I just would like to ask... Is it possible that you can detect whether a
Windows Service is existing or not? If this is possible, how can you
implement it?

Thank you!

A

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.668 / Virus Database: 430 - Release Date: 04/24/2004
Nov 16 '05 #4

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

Similar topics

2
by: r | last post by:
Hi, I would like to check from within my c# app, if certain services are up or down, to activate and to stop them. Any idea on how to do it? Thanks in advance
4
by: Simon Verona | last post by:
My software relies on a third party data provider to a propretary database. In turn the third party database relies on a Windows Service that runs on the server to supply the data... The problem...
2
by: Jay Balapa | last post by:
Hello, We have a webservice which is called by our pocket pc apps. We have a need to filter data, so we want to add a another method on top to the existing method. Existing Service.asmx...
3
by: John Wright | last post by:
I need to know how to check the state of a windows service. I need to determine if the windows service "Smart Card" is running. If it is not running, I need to start the service. Also it would...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.