Reputation: 645
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:
Upvotes: 4
Views: 13265
Reputation: 645
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.
Upvotes: 4