Results 1 to 3 of 3

Thread: Windows Service does not appear under services.msc is called

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2018
    Posts
    21
    Rep Power
    9

    Windows Service does not appear under services.msc is called

    I have developed a Windows Service, and it will be incumbent on me to develop it further. Haplessly, a great obstacle for this is the fact that it does not appear in the service list after services.msc is called even though installation works quite finde with InstallUtils.exe.

    The main-class looks like this:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    
    namespace WindowsService1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main()
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] 
                { 
                    new Scheduler() 
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
    }
    The service has a scheduler like this:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Timers;
    
    namespace WindowsService1
    {
        public partial class Scheduler : ServiceBase
        {
            private Timer timer1 = null;
    
            public Scheduler()
            {
                InitializeComponent();
            }
    
            private void timer1_Tick(object sender,ElapsedEventArgs e)
            {
                Library.WriteErrorLog("Timer ticked.");
            }
    
            protected override void OnStart(string[] args)
            {
                timer1 = new Timer();
                this.timer1.Interval = 30000;
                this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
            }
    
            protected override void OnStop()
            {
                timer1.Enabled = false;
                Library.WriteErrorLog("WindowsService1 stopped.");
            }
        }
    }
    ...and there is a library class there, too, which simply writes some text into log files (this is what it is supposed to do for the time being):

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace WindowsService1
    {
        public static class Library
        {
            public static void WriteErrorLog(Exception ex)
            {
                StreamWriter sw = null;
                try 
                {
                    sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\LogFile.txt",true);
                    sw.WriteLine(DateTime.Now.ToString()+": "+ex.Source.ToString().Trim()+"; "+ex.Message.ToString().Trim());
                    sw.Flush();
                    sw.Close();
                }catch{}
    
            }
    
            public static void WriteErrorLog(string Message) 
            {
                StreamWriter sw = null;
                try
                {
                    sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\LogFile.txt", true);
                    sw.WriteLine(DateTime.Now.ToString() + ": " + Message);
                    sw.Flush();
                    sw.Close();
                }
                catch { }
            }
    
        }
    }
    The project installer file has two sets of properties: serviceInstaller1:
    GenerateMember: True
    Modifiers: Private
    DelayedAutoStart: False
    Parent: ProjectInstaller
    ServiceName: Service1
    ServiceDependsOn: String[]Array
    StartType: Manual

    ... as well as serviceProseccinstaller1:

    GenerateMember: True
    Modifiers: Private
    Account: LocalSystem
    Parent: ProjectInstaller

    What hack is needed to make the service appear where it should after installation?

    Btw.: Is it allowed to upload zip-files with project data instead of pasting the classes into the forum editor window?

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,979
    Rep Power
    154
    Quote Originally Posted by aindrea View Post
    Is it allowed to upload zip-files with project data instead of pasting the classes into the forum editor window?
    If you click the Go Advanced button then the advanced editor will allow you to upload attachments, including ZIP files. You should start by deleting the 'bin' and 'obj' folders from all projects because they contain binaries, which are not allowed in attachments. You can then zip the solution folder and attach the result. That said, attaching whole projects should never be your first choice. Posting relevant code directly should always be the first option.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2018
    Posts
    21
    Rep Power
    9
    After all, my service is visible now. It seems that I used the wrong installation tool. Instead of install utils I did it like this:

    sc.exe create WindowsService1 binPath="<my path to>\WindowsService1.exe"

    Now it is clearly visible.

Similar Threads

  1. connect windows service to sql
    By hamid.abbaszadeh.mail in forum Windows Services
    Replies: 3
    Last Post: 10-30-2016, 9:10 PM
  2. Question How to update the GUI on the WCF Service side when a method is called from the Client
    By viswaroopan in forum Windows Communication Foundation (WCF)
    Replies: 5
    Last Post: 10-16-2015, 7:03 PM
  3. web service + win service
    By ytzkey in forum Windows Services
    Replies: 1
    Last Post: 08-08-2014, 5:12 AM
  4. Question Where to put my code in a Windows Service skeleton
    By bradwoody in forum Windows Services
    Replies: 2
    Last Post: 09-23-2011, 10:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •