ASAP HELP NEEDED Windows Service set to automatic (start up) but doesn't start everytime after rebooting PC

I have a windows service that is supposed to start automatically. Well when I reboot the PC it does not start everytime.

I am not sure why this is happening. Does anyone have any suggestions on what I can do to make this work.

here is the installer file

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
using Microsoft.Win32;

namespace EventListenerOCS
{
   /// <summary>
   /// Summary description for ProjectInstaller.
   /// </summary>
   [RunInstaller(true)]

   public class EventListenerOCSInstall : System.Configuration.Install.Installer
   {
      ServiceInstaller serviceAdmin = new ServiceInstaller();

      public const int MSGBOXONTOPKEY  =  256;

      /// <summary>
      /// Required designer variable.
      /// </summary>
      public QTIEventListenerOCSInstall()
      {
         // TODO: Add any initialization after the InitializeComponent call

         process.Account = ServiceAccount.LocalSystem;
         
         serviceAdmin.StartType      = ServiceStartMode.Automatic;
         serviceAdmin.ServiceName    = "QTIEventListenerOCS";
         serviceAdmin.DisplayName    = "QTIEventListenerOCS";

//         this.serviceAdmin.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
         
         /// <Summary >
         // Now just add the installers that we created to our
         // parents container.
         /// </Summary >
         Installers.Add( process );
         Installers.Add( serviceAdmin );

         // Here is where we set the bit on the value in the registry.
         // The 256 value will enable the messagebox to stay on top of all running
         // applications. However it may not be supported from Microsoft with newer
         // operating systems.
         RegistryKey ckey = Registry.LocalMachine.OpenSubKey(
            @"SYSTEM\CurrentControlSet\Services\EventListenerOCSInstall", true);
         if(ckey != null)
         {
            // Ok now lets make sure the "Type" value is there,
            //and then do our bitwise operation on it.
            if(ckey.GetValue("Type") != null)
            {
               ckey.SetValue("Type", ((int)ckey.GetValue("Type") | MSGBOXONTOPKEY));
            }
         }
      }
   }
}



here is the other file

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Timers;

using EventListenerOCS;

namespace EventListenerOCS
{
   public class EventListenerOCS : System.ServiceProcess.ServiceBase
   {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;
      private ServerSocket server;
      protected Thread              m_thread;
      protected ManualResetEvent    m_shutdownEvent;
      protected TimeSpan            m_delay;
      private System.Timers.Timer m_timer = null;

      public static bool m_bIsDisplayed = false;    

      /// <summary>
      /// This is used for the messagebox. If displayed or not (True/False)
      /// </summary>
      public static bool m_IsDisplayed
      {
         get { return m_bIsDisplayed; }
         set { m_bIsDisplayed = value;}
      }

      public EventListenerOCS()
      {
         // This call is required by the Windows.Forms Component Designer.
         InitializeComponent();

         // TODO: Add any initialization after the InitComponent call
      }

      // The main entry point for the process
      static void Main()
      {
         System.ServiceProcess.ServiceBase[] ServicesToRun;
      
         // More than one user Service may run within the same process. To add
         // another service to this process, change the following line to
         // create a second service object. For example,
         //
         //   ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
         //
         ServicesToRun = new System.ServiceProcess.ServiceBase[] { new EventListenerOCS() };

         System.ServiceProcess.ServiceBase.Run(ServicesToRun);
      }

      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         components = new System.ComponentModel.Container();
         this.ServiceName = "QTIEventListenerOCS";
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      /// <summary>
      /// Set things in motion so your service can do its work.
      /// </summary>
      protected override void OnStart(string[] args)
      {
         // TODO: Add code here to start your service.
         // Create the timer if one is needed.
         m_timer = new System.Timers.Timer();
         m_timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerTaskElapsed);

         // Always wait a minute on startup so the service starts correctly on reboot.
         m_timer.Interval = 120000;  
         //m_timer.Start();
         m_timer.Enabled = true;
         
         server = new ServerSocket();
         server.StartServer();
      }

      protected void TimerTaskElapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
         // The timer will be started again once tasks are completed.
         //m_timer.Stop();
         m_timer.Enabled = false;
      }
 
      /// <summary>
      /// Stop this service.
      /// </summary>
      protected override void OnStop()
      {
         // TODO: Add code here to perform any tear-down necessary to stop your service.
         // The timer will be started again once tasks are complete.
         //m_timer.Stop();
         m_timer.Enabled = false;
         // Stop the Server. Release it.
         server=null;
      }
   }
}
LVL 2
NewMom2BrandonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheAvengerCommented:
Have a look at the event log of the machine. It will tell you if the service failed and why.
0
NewMom2BrandonAuthor Commented:
I just get a timed out message
0
NipNFriar_TuckCommented:
You may want to check the dependencies of the service... If your service depends on another ( like SQL Server ) it may not be able to start until the other start and times out while waiting.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

deeptinayakCommented:
Where are you starting the timer?
m_timer.Start()?
0
NewMom2BrandonAuthor Commented:
I found out the problem. The place I am trying to start the service on has the desktop locked out. So the only way I can make the service start on reboot. is to change it from automatic to manual and run a batch file.

This eliminated all of my issues
0
NewMom2BrandonAuthor Commented:
I also found this which was helpful as well

http://www.codeproject.com/csharp/SercviceInstallerExt.asp
0
CetusMODCommented:
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.