1
votes

I am trying to start my Windows services application but i am getting the following error

Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.

Could someone please help me on this..

2
When you say "start" do you mean start in the debugger, or start an installed service? If you don't install a service, it can't run as a service.spender
A good way to debug a service is to place System.Diagnostics.Debugger.Break() in the startup and then to install and start it. You'll be offered an opportunity to attach the debugger when you hit the breakpoint.spender
Have a look at TopShelf (topshelf-project.com), a good framework for Windows servicesNeil Stevens
The error itself explains everything: install the executable as a service with InstallUtil (execute InstallUtil without params for help) and then start it with NET START (servicename)Gusman

2 Answers

1
votes

As they say in the comments - you can't start a windows service unless you install it and run it from the Service Manager (Services)

A solution: I would recommend to add a console main entry point in your C# service program so you can actually start it from both the Service Manager and debugger / exe execution.

http://einaregilsson.com/run-windows-service-as-a-console-program/

0
votes

when you have builded your windows service you have to install it before you can start it: here is the install command line:

installutil YourNewService.exe

You see then the new service in windows service manager, where you can start and stop it.

And don't forget to unistall your new service before you try again with a new build version.

Look here for more informations: How to: Install and Uninstall Services

best regards