Question

I created an application as a Windows Service which works fine on my workstation running Windows 8 x64, and writes several events in the Application eventlog on OnStart(). I used InstallUtil to install it on a Windows 2012 machine and it stops right after it starts. The only thing I see regarding it in the eventlog is under System:

The Foo service entered the stopped state. 
  • I can't even debug it on that machine without installing VS2012 which I don't want to do because it is in a production environment.
  • The application depends on one DLL which is copied locally.
  • .NET Frameworks 2.0 to 4.5 are installed on both machines.
  • I tried Run as Administrator under Compatibility but it's set to run under LocalService anyways so it should have permission to do everything it's tasked to do...

EDIT 1: why would you downvote the question without even leaving a remark as to why it's bad?

Was it helpful?

Solution

Few things I have learned on debugging windows services that might help you in troubleshooting your issue.

  1. Try to log everything for each method inside your windows service to text file as Tim suggested in the comment.
  2. Try to catch UnhandledException before the service exits by adding an event handler to the appdomain. I have my Log function that writes to text file.

    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException

    Public Sub CurrentDomain_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs)
            'Log and output exception message before the application exits.
            Dim exp = DirectCast(e.ExceptionObject, Exception)
            Dim formatexp = String.Format("Exception: {0}; Message: {1}: InnerException: {2}",
                              exp.ToString(),
                              exp.Message.ToString(),
                              exp.InnerException.ToString())
            Log(formatexp)
            Console.WriteLine(formatexp)
    
            Log("Application exited due to unhandled exception")
            Console.WriteLine("Service exited due to unhandled exception")
            'Exit the batch process gracefully.
            Environment.Exit(-1)
    End Sub
    
  3. Try using WindDbg for debugging Windows Service Crash or Hang issues and you can download it from Microsoft Download site.

  4. Check if service account that is trying to access any resource on the server has access to them.

  5. If you want to see real time execution of your code then log execution to a SignalR Host. This might be overkill but I once had multiple threads executing different processes and I was able to debug an issue using SignalR.

Note: If you can post some sample code then it would be helpful to us in helping you out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top