Question:
I have created an installer for a windows service with Visual Studio 2012 and InstallShield.
The service runs fine.
The installer runs fine on my
Solved by writing my own installer.
All I do is embed the output of the service project as resources into the installer project, and write them to a specified folder.
Then I run installutil programmatically, which installs the service just fine, and then it works.
The only drawback compared to a real installer is, this way there is no uninstaller, but I don't care anymore. When it's days faster to roll your own installer than using InstallShield, then there is something wrong with InstallShield.
Reinventing the wheel may lead to errors, but at least they are mine to make and solvable.
Here the solution, in case it is useful to anybody else.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace SimpleInstaller
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
if (false)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
//for (int i = 0; i < args.Length; ++i)
//{
// Console.WriteLine("args[{0}] = {1}", i, args[i]);
//}
string strPath = @"C:\pro\DbBackupService\DbBackupService\bin\Debug\DbBackupService.exe";
string[] callArgs = null;
string[] argInstall = new string[] { strPath };
string[] argUnInstall = new string[] { "/u", strPath };
bool bIsInstallation = true;
bIsInstallation = false;
callArgs = bIsInstallation ? argInstall : argUnInstall;
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture();
//if(Console.OutputEncoding.CodePage != 65001 && Console.OutputEncoding.CodePage !=
if (Console.OutputEncoding.CodePage != 65001
&& Console.OutputEncoding.CodePage != System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.OEMCodePage
&& Console.OutputEncoding.CodePage != System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.ANSICodePage)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
}
try
{
System.Configuration.Install.ManagedInstallerClass.InstallHelper(callArgs);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//return -1;
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine(" --- Press any key to continue --- ");
Console.ReadKey();
return 0;
} // End Sub Main
} // End Class Program
} // End Namespace SimpleInstaller
Solved by overriding all the methods of Custom action in my Installer class. After making lot of try,finally it works like a charm.
public override void Install(IDictionary savedState)
{
base.Install(savedState);
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
Error code 1001 ALWAYS means a failure in the Installer class custom action. InstallShield is merely consuming / hosting it as you directed. Installer Class custom actions are notoriously brittle and run out of process so you get very little logging.
Instead of using the custom action, you should use the native Windows Installer ServiceInstall and ServiceConfigure tables as exposed by InstallShield under the advanced component settings. Create a component, add your service EXE to it as a key file and then define the service meta.
First I suggest merely creating the install and then starting it by hand after the install. Once that is working add the ServiceControl information so the installer does it automatically. Rinse and repeat on a VM.
If you get an error 1920 when the installer try's to start the service this is always a service problem. Profile it to understand the problem and then either fix the code or fix the installer if it's missing a dependency.