4

I have been trying with no avail to get this service to install.

I am currently using InnoSetup since the Visual Studio installer just didn't entirely make sense to me, to be honest (It is also 1am. D:)

I took some of the code from this thread: Inno Setup for Windows service?

And everyone there says it worked perfectly for them, but they don't entirely explain what they did or where they put that code. Was it a console application? Where?

So, I stuck it where I thought it might have supposed to go. When you add an installer class to a service, a 'Program.cs' class gets created, so that is where I put it.

Here is my 'Program.cs':

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration.Install;
using System.Reflection;

namespace Installer
{
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    {
        Console.WriteLine("MASDjhd");
        string parameter = string.Concat(args);
        switch (parameter)
        {
            case "--install":
                ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                break;
            case "--uninstall":
                ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                break;
          }

        }
    }
}

Here is my InnoScript:

[Setup]
AppName=MachineVerification
AppVersion=1.0
DefaultDirName={pf}\MachineVerification
DefaultGroupName=MachineVerification
UninstallDisplayIcon={app}\MachineVerification.exe
Compression=lzma2
SolidCompression=yes

[Files]
Source: "Installer.exe"; DestDir: "{app}"

[Run]
Filename:"{app}\Installer.exe"; Parameters: "--install"

[UninstallRun]
Filename: "{app}\Installer.exe"; Parameters: "--uninstall"

Help? D:

Community
  • 1
  • 1
Madeline
  • 645
  • 1
  • 9
  • 19
  • With this installer, you do need all the dll's inside the same area as the executable, right? I'm coming from using an MSI installer which handled everything so I'm just trying to double check. – Dinerdo Jul 26 '17 at 14:44

1 Answers1

4

Found my answer here: Self install windows service in .NET c#

For those you who want to follow the link, the solution is to add:

        var processInstaller = new ServiceProcessInstaller();
        var serviceInstaller = new ServiceInstaller();

        //set the privileges
        processInstaller.Account = ServiceAccount.LocalSystem;

        serviceInstaller.DisplayName = "MachineVerification";
        serviceInstaller.StartType = ServiceStartMode.Automatic;

        //must be the same as what was set in Program's constructor
        serviceInstaller.ServiceName = "MachineVerification";
        this.Installers.Add(processInstaller);
        this.Installers.Add(serviceInstaller);

to the constructor of your install class in your service.

Community
  • 1
  • 1
Madeline
  • 645
  • 1
  • 9
  • 19