Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Windows Service start / stop another Windows Service?

How can one Windows Service stop / start another Windows Service?


Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

you would use the ServiceController class http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemserviceprocessservicebaseclasstopic.asp MSDN includes examples of starting / stopping
ASKER CERTIFIED SOLUTION
Avatar of Fahad Mukhtar
Fahad Mukhtar
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

I'll come back with questions if I have any...thanks.
hmm ... from now on Im just gonna copy/paste the stuff in MSDN
dont you hate their linking system where you are on the right thing but the link is the wrong link :)
?
the link I put up points to servicebase not servicecontroller

when you click through their links they dont always update the displayed address ... so the msdn link didnt have the proper examples.

although in general I think I am going to start copy/pasting because people tend not to bother reading links :) that and you are sure it doesnt die for the PAQ
I usually don't like links, esp for 500 point questions.  Not to say they aren't helpful....I've just gotten a lot of links in the past that really don't show that the Expert understood my problem.
I agree there are some experts who pretty much give a top 3 google search back :)
I've come to realize this.....and will specifically ask Experts NOT to Google......I can GOOGLE, for crying out loud!

I think when I come into this forum I am looking for an answer FAST, yes, but I am also looking for someone more experienced than me to explain the answer a little bit (would be my hope).

For 50 or 100 points....I don't expect much more than a few links thrown at me.

For 500 points I expect a little bit more.

================================

For paying customers like myself....what do points mean, anyways??????  Not that I'm complaining....but if you're Bill Gates and you spend 300 millions dollars...you still have 50 billion and will earn that money right back in a few months anyway.
I used that code myself that i have provided about 1 year ago in almost same kind of problem... i didnt search it on google .. .i prefer to use msdn but for help and not for it for copy paste ... you cant find such code on google or in msdn
Desp:

In your sample code.....how do I know what to pass in (to replace "Messenger") with my actual Windows Service name?

System.ServiceProcess.ServiceController myController =   new System.ServiceProcess.ServiceController("Messenger");
the same thing you would pass to net stop "service" ... its the name of your service
Okay....makes sense.....I'm goofy as usual.
the answer lies in the first line of the answer you have accepted:)
>>>>The following 4 lines will manipulate the "Messenger" Service ... you can replace it by your own service name...
Yep.....got it working.

That was a really dumb question of mine.....I know, I know.......I'm just goofy.

Tom