3
votes

I have a Windows service which I can install on my local machine using installutil no problem.

Now, this service has to be installed on a server. I copy all files to the server and run the same command, set the service to log on as a local user account and when the service starts I get an error saying "logon failed" - okay so perhaps the user account is the issue.

So I change the service log on as to local system account. I start the service and I am told "The service did not respond to the start or control request in a timely fashion".

So I googled and tried various solutions but to no avail. So I got to thinking maybe it was something in the OnStart method which broke (even though I have logging calls which never logged). So I removed all code from the OnStart event and still the service would not start, I got the "timely fashion" error.

So where am I at? I believe it could be due to the references I have defined in the project. To test this I created a new Windows service template from VS2012 with no references (other than the default ones) and I can start the service. No issues.

So my question is what could be causing this? In my project the references point to locations which do not exist on the server, however the directory where the service resides has all the referenced DLLs.

Edit: Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace RetrieveAndProcessSecurityLogs
{
    static class Program
    {
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
            new LogService()
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

LogService.cs

public partial class LogService : ServiceBase
{
    public LogService()
    {
        InitializeComponent();
        this.ServiceName = "Retrieve and Process Security Logs";
        this.CanPauseAndContinue = true;
        this.CanStop = true;
    }

    protected override void OnStart(string[] args)
    {
        //...
    }

    protected override void OnStop()
    {
        //...
    }

Edit: The installed .NET version on the server is v4.0, however in the app config file for the project there is this line:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

Could the 4.5 part be the issue?

Edit2: Bottom line: if I reference a DLL, I get the timely fashion error. If I have no extra DLL reference defined the service starts.

Sorry for the story. Andrew

1
it is almost certainly permissions related. but no code = no answer.Mitch Wheat
What code would you like? The project has several files, classes, interfaces, etcandrewb
Start with the code in your program.cs and your service initialization.VahidNaderi
The OnStart you left out is where your problem lies, please include it. If from the launching of the exe to the completion of OnStart takes more than 30 sec then you get the error you are getting. One of the steps between the entry point of Main and the last line of OnStart is the culprate so we need to see all of those lines.Scott Chamberlain
It does not get to the OnStart - I use EnterpriseLibrary for logging, the first line is to write DateTime.Now to log and it does not get logged. Also this is not after 30 seconds. As soon as I click start I receive the error.andrewb

1 Answers

3
votes

For future reference to anyone who encounters this issue, the issue was one of the references was built against .NET FW 4.5 and on the server where the service was being installed had .NET FW 4. My machine had 4.5.