Reputation: 17293
I used this tutorial to create C# Windows service using Visual Studio 2010 and its stock console app project, but after I changed everything and tried to install it as such:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil" /i myservice.exe
I don't see my service in the list of services through Control Panel. I then checked the output from the installutil
and found this message:
Remove InstallState file because there are no installers.
I'm not sure why it says it because I do have an installer class, defined as such:
namespace MySrvr
{
class MyServiceInstaller : System.Configuration.Install.Installer
{
public MyServiceInstaller()
{
ServiceProcessInstaller process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
ServiceInstaller serviceAdmin = new ServiceInstaller();
serviceAdmin.StartType = ServiceStartMode.Automatic;
serviceAdmin.ServiceName = "MyServiceName";
serviceAdmin.DisplayName = "My Service Display Name";
serviceAdmin.Description = "My Service Description";
Installers.Add(process);
Installers.Add(serviceAdmin);
}
}
}
So what am I doing wrong here?
Upvotes: 2
Views: 1096
Reputation: 17293
OK, I got it. Two errors:
The installer class must be declared as public
It must have [RunInstaller(true)]
attribute in front of it.
As such:
namespace MySrvr
{
[RunInstaller(true)]
public class MyServiceInstaller : System.Configuration.Install.Installer
{
}
}
The version of installutil
has nothing to do with it.
Upvotes: 5