Skip to content

Windows Service GUI Home

DAVIDSystems edited this page Jun 18, 2018 · 6 revisions

Welcome to the WindowsServiceGUI Documentation

The WindowsServiceGUI helps you to develop, debug and test c# based windows services.

All you have do is, to add a single .NET assembly to you project. If the servicerunner.dll is included in your windows service project you can debug and start your service like a normal application. If the service is started as a windows service, no GUI is displayed or executed. The service behaves like normal and is started and stopped by the system.

Service GUI

WindowsServiceGUI detects automatically if the application is started as a service or as application. If started under a debugger or as a normal application a windows-gui is displayed which allows to simulate the 'Start' and 'Stop' methods of a windows service. Simply click the 'Start' or 'Stop' Button. The application-dialog consists of a log window, which makes it possible to display logmessages from every point in the code.

Reasons to use such a solution for developing windows services.

  • no need to stop a running service, during compile and update. => start, debug and exit the service like any other application
  • pure console output is not appealing to everyone, especially under windows. => direct log-output in a window (Copy and Paste as from any other application)
  • give it to others, which can test the service, without need to install a service => just start the service, like a normal application => install it, when the service is tested and everything works as it should !

HowTo:

1. Add assembly to the windows service project

Solution

2. Update the Program.cs file in your service-project

using DigaSystem.ServiceRunner;

namespace ServiceRunnerTest
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)        {
            ServiceBaseEx[] ServicesToRun;
            ServicesToRun = new ServiceBaseEx[]
            {
                new TestService()
            };

            if (ServiceRunner.RunningAsService)
            {
                ServicesToRun.LoadServices();
            }
            else
            {
                ServicesToRun.StartServices();
            }
        }
    }
}

3. Inherit the main service class from ServiceBaseEx instead of ServiceBase


using DigaSystem.ServiceRunner;

namespace ServiceRunnerTest
{
    public partial class TestService : ServiceBaseEx
    {
        public TestService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            LogMessage("Successfully started Test Service !");
        }

        protected override void OnStop()
        {
            LogMessage("Successfully stopped Test Service !");
        }   
     }
}

4. LogMessages

LogMessage(string msg) is a static function of the ServiceBaseEx, so you can call it in your service class directly or anywhere in your code like:

ServiceBaseEx.LogMessage(string msg);

5. Install / Uninstall / RunAs Administrator

SysMenu

RunAs:

The GUI is able to install the windows service. If the application is not started as Administrator, you need to restart as Administrator, because this is necessary for installing a service. This can be easily done with the menu-function 'Run as Administrator'.

Install:

To install the application as service, you need to enter the necessary information. This can be accomplished with the following dialog.

Install Dialog

Uninstall:

you can uninstall the service via the 'uninstall' feature. The following dialog is displayed. The application remembers the servicename on successfull installation, so you don't need to enter it again !

Uninstall Dialog

6. System Requirements

  • The projects are compiled with Visual Studio 2017
  • The ServiceRunner projects runs on .NET 4.5
  • The Assembly has no additional dependencies
  • The TestService is set to .NET 4.6.2, but runs also with 4.5
  • The project is inspired by Anderson Imes - ServiceProcess.Helpers