?
Solved

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

Posted on 2004-11-30
8
Medium Priority
?
185 Views
Last Modified: 2012-05-05
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;
      }
   }
}
0
Comment
Question by:NewMom2Brandon
7 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12715213
Have a look at the event log of the machine. It will tell you if the service failed and why.
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 12715636
I just get a timed out message
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12716728
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:deeptinayak
ID: 12716781
Where are you starting the timer?
m_timer.Start()?
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 12718084
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
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 12718125
I also found this which was helpful as well

http://www.codeproject.com/csharp/SercviceInstallerExt.asp
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 12748128
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question