How to run .NET services from command line? net start "Sample Service" is not working.
Services are not supposed to be started from command line. First register it (installutil /i service_path) then start with net start or sc start.
Alternatively, create Main entry point in service project and start your logic, so you can test your service from command line. However this won't be real service environment.
You can start or stop a service by calling:
net start "Service Name"
net stop "Service Name"
For details, see this technet article.
This should work, provided the following are true:
- The command prompt/user has the appropriate permissions to start the service. This will be required for ANY solution.
- The service is installed and registered correctly with the system. My suspicion is that this may be the culprit. Is the service listed under services?
Make sure that you add an installer to your Windows service. You have to do this in order for the InstallUtil.exe utility to work. You can see how to that here.
After you add the installer, InstallUtil.exe can be used to install and uninstall your service.
- Install:
InstallUtil.exe <YourServiceExecutable>
- Uninstall:
InstallUtil.exe /u <YourServiceExecutable>
To start and stop your service, use Reed's solution.
If you want to get fancy, you can add some command-line logic to your service that will allow you to do all of this (install-and-start/stop-and-uninstall) directly from your service, i.e., you won't have to use InstallUtil.exe anymore. That solution is here.