473,847 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service is running?

How do I check to see if a particular service is running?
Nov 21 '05 #1
3 1481
Kevin,
I normally use ServiceControll er.Status:

http://msdn.microsoft.com/library/de...tatusTopic.asp
' Toggle the Telnet service -
' If it is started (running, paused, etc), stop the service.
' If it is stopped, start the service.
Dim sc As New ServiceControll er("Telnet")
Console.WriteLi ne("The Telnet service status is currently set to
{0}", sc.Status)

If sc.Status = ServiceControll erStatus.Stoppe d _
Or sc.Status = ServiceControll erStatus.StopPe nding Then
' Start the service if the current status is stopped.
Console.WriteLi ne("Starting the Telnet service...")
sc.Start()
Else
' Stop the service if its status is not set to "Stopped".
Console.WriteLi ne("Stopping the Telnet service...")
sc.Stop()
End If

' Refresh and display the current service status.
sc.Refresh()
Console.WriteLi ne("The Telnet service status is now set to {0}.",
sc.Status)

If you are changing the status, ServiceControll er.WaitForStatu s can be
useful:

http://msdn.microsoft.com/library/de...atusTopic1.asp

For example, to "restart" a service I use something like:

Dim sc As New ServiceControll er("Telnet")
sc.Stop()
sc.WaitForStatu s(ServiceContro llerStatus.Stop ped)
sc.Start()

Hope this helps
Jay

"Kevin L" <no_spam@not_re al_email.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
How do I check to see if a particular service is running?

Nov 21 '05 #2
In article <#c************ *@TK2MSFTNGP15. phx.gbl>, Kevin L wrote:
How do I check to see if a particular service is running?


You might want to check out the System.ServiceP rocess.ServiceC ontroller
class...

Looks like you should be able to do something like...

Imports System.ServiceP rocess

....

Dim controller As New ServiceControll er ("YourSeviceNam e")
Console.WriteLi ne (controller.Sta tus)

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #3
Thanks Jay. Exactly what I need.

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Kevin,
I normally use ServiceControll er.Status:

http://msdn.microsoft.com/library/de...tatusTopic.asp
' Toggle the Telnet service -
' If it is started (running, paused, etc), stop the service.
' If it is stopped, start the service.
Dim sc As New ServiceControll er("Telnet")
Console.WriteLi ne("The Telnet service status is currently set to
{0}", sc.Status)

If sc.Status = ServiceControll erStatus.Stoppe d _
Or sc.Status = ServiceControll erStatus.StopPe nding Then
' Start the service if the current status is stopped.
Console.WriteLi ne("Starting the Telnet service...")
sc.Start()
Else
' Stop the service if its status is not set to "Stopped".
Console.WriteLi ne("Stopping the Telnet service...")
sc.Stop()
End If

' Refresh and display the current service status.
sc.Refresh()
Console.WriteLi ne("The Telnet service status is now set to {0}.",
sc.Status)

If you are changing the status, ServiceControll er.WaitForStatu s can be
useful:

http://msdn.microsoft.com/library/de...atusTopic1.asp

For example, to "restart" a service I use something like:

Dim sc As New ServiceControll er("Telnet")
sc.Stop()
sc.WaitForStatu s(ServiceContro llerStatus.Stop ped)
sc.Start()

Hope this helps
Jay

"Kevin L" <no_spam@not_re al_email.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
How do I check to see if a particular service is running?


Nov 21 '05 #4

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

Similar topics

2
2774
by: Russ McDaniel | last post by:
Originally posted to microsoft.public.dotnet.distributed_apps with no response. Reposted here with additional thoughts. --- Hello, I'm writing a Windows service which performs some potentially long-running, uninterruptable processes. When the service starts, I create a separate worker thread to perform the work so as to not block the service control manager upon startup. The design quandry I'm running into though is how best
3
2221
by: Brad Jones | last post by:
Hello, I'm hoping someone can give me some help or guidance here. I'm not sure if this is even the best group to post to for this. Our OEM equipment's software architecture relies heavily on a "master" windows service. This responsibility of this service is to launch 10 or so other applications, some of which have GUI's. These applications need to be running whether somebody is logged in or not. There is no communication required between...
7
6941
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that will function as a windows service and will also present a GUI to the user. I don't want "Interact with desktop"; I want the same exe to run as a normal non-interactive service when started properly by the service control manager, or instead to run...
7
712
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: service 1 - my service watches service 2 - windows service service 2 is stopped - service 1 starts service 2
9
7275
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
7605
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...
8
1433
by: Jerry Camel | last post by:
I want my service to terminate automatically if the specified parameters are invalid. I tried to use a servicecontroller component to attach to the service, but I think that it's failing because it's being called in the OnStart event (where I validate the parameters) and the service isn't fully running yet. How can I stop my service from within the service itself? Thanks. Jerry
3
8010
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that libraries I made myself were not having this problem, but it only happened with a zip library I downloaded and copied into my program's directory. When using classes from this library, my service threw an "Access Is Denied" FileLoadException, which...
10
1539
by: JLuis Estrada | last post by:
Hi there Its my 1st post in this group and I hope we could have a great time. well, this is my problem I was debbuging my app (a website) and the system get stuck and I had to reboot the system. Since that day, everytime I tried to open the VS2003 and run my app, the system showed me a message like:
12
14544
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
0
9734
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
10995
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10718
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9493
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7888
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
7061
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();...
0
5729
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...
1
4540
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
2
4130
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.