Using ServiceController to Start/Stop service not working

380 views
Skip to first unread message

Marcia Cupery

unread,
Jun 25, 2014, 3:28:10 PM6/25/14
to topshelf...@googlegroups.com
Hi, I'm sorry to ask this because I'm sure there is a simple explanation but I cannot find it anywhere.  (And, obviously, I am new to TopShelf.)

I have a separate application that I am writing to monitor a service that uses TopShelf.  After installing the service, I can connect to the service using ServiceController and get its status.  However, I cannot Start or Stop the service using ServiceController.  When the service is stopped and I try to start it using ServiceController.Start(), I get this exception message:  "Cannot open <service name> service on computer '.' "

In the Program.cs of the service, the service is started using the same methodology as the sample code:
        HostFactory.Run(x =>                                 //1
        {
            x.Service<TownCrier>(s =>                        //2
            {
               s.ConstructUsing(name=> new TownCrier());     //3
               s.WhenStarted(tc => tc.Start());              //4
               s.WhenStopped(tc => tc.Stop());               //5
            });


Is there something about this that needs to be changed in order for the ServiceController to be able to start/stop the service?

Thanks in advance,
Marcia

Travis Smith

unread,
Jun 25, 2014, 6:48:06 PM6/25/14
to topshelf...@googlegroups.com
Are you running your secondary service as admin? It might be a permissions problem. 
--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
-Travis

Marcia Cupery

unread,
Jun 25, 2014, 8:45:05 PM6/25/14
to topshelf...@googlegroups.com
Travis,

It was indeed a permissions problem.  I did not realize the application needed to be run as Administrator in order for the calls to Start and Stop to work.  All is well now.  Thanks for the quick response!

Marcia
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
-Travis
Reply all
Reply to author
Forward
0 new messages