I have a windows service application. When I press the button, I want to start the service. But I’m receiving the following the error.
Window Service Start Failure:
Cannot start service from the command line or debugger. A Windows
Service must first be installed (using installutil.exe) and then started
with the ServerExplorer, Windows Service Administrative tool or the NET
START command.
C# Code:
namespace WindowsFormsApplication1
{
partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
RegistryKey KEY = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\baslat", true);
KEY.DeleteValue("timer",true);
}
protected override void OnShutdown()
{
RegistryKey KEY = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\baslat", true);
KEY.SetValue("timer","");
}
}
}
It’s telling you what to do. You need to install the service inside windows. Then you can stop and start it using the windows service control manager.
You can’t start it like an exe as services have different entry points. However there is nothing stopping you from having an exe that runs under the SCM and as a normal program.