title: Visual C# - Service Runs On Windows 7 but not Windows 10
body: <p>I have a custom service that runs alongside another application. The service manages the database that the application relies on. The application installs and runs perfectly on Windows 7 machines, but when running the application on Windows 10, the service does not start. When both installing and running the application I make sure to run them as an administrator.</p>
  
  <p>Looking at the task manager, after the service has started and failed, the service shows but the status is "stopped". I have tried commenting out the functioning body of the code but the status of the service still shows as "stopped".</p>
  
  <p>I have been stuck with this problem for a while now and debugging it is not easy. The program is being compiled using Framework 3.5. Any help would be greatly appreciated.</p>
  
  <p>You can find the code below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Diagnostics;
  using System.ServiceProcess;
  using System.Text;
  using System.Collections;
  using System.Runtime.Remoting;
  using System.Runtime.Remoting.Channels;
  using System.Runtime.Remoting.Channels.Tcp;
  using Chant.Datatest.Database;
  using System.Configuration.Install;
  using System.Security.Permissions;
  using Chant.Common;
  using System.IO;
  
  namespace Chant.Datatest.Server
  {
      [SecurityPermission(SecurityAction.LinkDemand)]
      public partial class DatatestDB : ServiceBase
      {
          TcpServerChannel serverChannel;
          CustomerDatabase m_database;
          ServerAdmin m_admin;
          AppSettings m_settings;
          System.Timers.Timer m_backupTimer;
          bool backupOS;
          int prevDay;
  
          public DatatestDB()
          {
              InitializeComponent();
              this.ServiceName = "chantDBsvc";
              this.CanShutdown = false;
              this.CanStop = true;
              this.AutoLog = true;
          }
  
          protected override void OnStart(string[] args)
          {
              try
              {
                  m_settings = new AppSettings();
                  BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
                  provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
  
                  IDictionary properties = new Hashtable();
                  properties.Add("port", m_settings.DBPort);
                  properties.Add("secure", true);
  
                  serverChannel = new TcpServerChannel(properties, provider);
                  ChannelServices.RegisterChannel(serverChannel, true);
  
                  m_database = new CustomerDatabase();
                  m_database.EnableAutoBackup = m_settings.EnableAutoBackup;
                  m_database.BackupCount = m_settings.BackupCount;
                  m_database.SetFilePath(m_settings.GetOldDBPath(), m_settings.LogFilePath);
                  m_database.LoadDatabase();
  
                  RemotingServices.Marshal(m_database, "DatatestDB.rem");
  
                  m_admin = new ServerAdmin(m_settings);
                  m_admin.DatatestDatabase = m_database;
  
                  RemotingServices.Marshal(m_admin, "DatatestAdmin.rem");
  
                  backupOS = false;
                  prevDay = DateTime.Now.Day;
  
                  m_backupTimer = new System.Timers.Timer();
                  m_backupTimer.Interval = 5000;
                  m_backupTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_backupTimer_Elapsed);
                  m_backupTimer.Start();
                  this.EventLog.WriteEntry("Chant DataTEST Server Started.  Database loaded from: " + m_settings.DBPath + ", Listening on port: " + m_settings.DBPort);
              }
              catch (Exception ex)
              {
                  this.EventLog.WriteEntry(ex.ToString());
              }
          }
  
          void m_backupTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
          {
              m_backupTimer.Stop();
  
              if (m_settings.EnableBackup)
              {
                  bool timeReached = TimeReached(m_settings.BackupTime);
                  bool doBackup = false;
                  if (timeReached)
                  {
                      switch (m_settings.BackupType)
                      {
                          case IntervalType.Daily:
                              m_database.CopyDatabase(m_settings.DBPath, m_settings.DBBackupPath);
                              break;
                          case IntervalType.Weekly:
                              switch (DateTime.Now.DayOfWeek)
                              {
                                  case DayOfWeek.Sunday:
                                      if (m_settings.OnSun)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Monday:
                                      if (m_settings.OnMon)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Tuesday:
                                      if (m_settings.OnTue)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Wednesday:
                                      if (m_settings.OnWed)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Thursday:
                                      if (m_settings.OnThur)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Friday:
                                      if (m_settings.OnFri)
                                          doBackup = true;
                                      break;
                                  case DayOfWeek.Saturday:
                                      if (m_settings.OnSat)
                                          doBackup = true;
                                      break;
                              }
                              break;
                          case IntervalType.Monthly:
                              if (DateTime.Now.Day == m_settings.MonthDay)
                                  doBackup = true;
                              break;
  
                      }
  
                      if (doBackup)
                          m_database.CopyDatabase(m_settings.DBPath, m_settings.DBBackupPath);
                  }
              }
  
              m_backupTimer.Start();
          }
  
          private bool TimeReached(DateTime timeIn)
          {
              bool reached = false;
              if ((timeIn.Hour &gt;= DateTime.Now.Hour) &amp;&amp;
                  (timeIn.Minute &gt;= DateTime.Now.Minute) &amp;&amp; (!backupOS))
              {
                  reached = true;
                  backupOS = true;
              }
  
              if (DateTime.Now.Day != prevDay)
              {
                  backupOS = false;
              }
              prevDay = DateTime.Now.Day;
  
              return reached;
          }
  
          protected override void OnStop()
          {
              m_database.SaveDatabase(true, false, null, "");
              this.EventLog.WriteEntry("Chant DataTEST Server Stopped.  Database saved to: " + m_settings.DBPath);
          }
      }
  
      [RunInstaller(true)]
      public class WindowsServiceInstaller : Installer
      {
          /// &lt;summary&gt;
          /// Public Constructor for WindowsServiceInstaller.
          /// - Put all of your Initialization code here.
          /// &lt;/summary&gt;
          public WindowsServiceInstaller()
          {
              ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
              ServiceInstaller serviceInstaller = new ServiceInstaller();
  
              //# Service Account Information
              serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
              serviceProcessInstaller.Username = null;
              serviceProcessInstaller.Password = null;
  
              //# Service Information
              serviceInstaller.DisplayName = "Chant DataTEST Server";
              serviceInstaller.StartType = ServiceStartMode.Automatic;
              serviceInstaller.Description = "Manages remote access to the Chant DataTEST customer database";
  
              //# This must be identical to the WindowsService.ServiceBase name
              //# set in the constructor of WindowsService.cs
              serviceInstaller.ServiceName = "chantDBsvc";
  
              this.Installers.Add(serviceProcessInstaller);
              this.Installers.Add(serviceInstaller);
          }
      }
  }
  </code></pre>