Install a .Net Windows Service Without Installutil.Exe

Install windows service without InstallUtil.exe

The InstallUtil.exe tool is simply a wrapper around some reflection calls against the installer component(s) in your service. As such, it really doesn't do much but exercise the functionality these installer components provide. Marc Gravell's solution simply provides a means to do this from the command line so that you no longer have to rely on having InstallUtil.exe on the target machine.

Here's my step-by-step that based on Marc Gravell's solution.

How to make a .NET Windows Service start right after the installation?

Install a .NET windows service without InstallUtil.exe

Yes, that is fully possible (i.e. I do exactly this); you just need to reference the right dll (System.ServiceProcess.dll) and add an installer class...

Here's an example:

[RunInstaller(true)]
public sealed class MyServiceInstallerProcess : ServiceProcessInstaller
{
public MyServiceInstallerProcess()
{
this.Account = ServiceAccount.NetworkService;
}
}

[RunInstaller(true)]
public sealed class MyServiceInstaller : ServiceInstaller
{
public MyServiceInstaller()
{
this.Description = "Service Description";
this.DisplayName = "Service Name";
this.ServiceName = "ServiceName";
this.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
}
}

static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "uninstalling" : "installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}

Install windows service without using InstallUtil or Setup Installation

I have provided a step-by-step solution for how to add command-line install/uninstall to your Windows service using C#. This solution lets you avoid requiring the use of InstallUtil.

How to make a .NET Windows Service start right after the installation?

Installing a windows service without a set up project

You can use installutil.exe in an elevated command window for this, as you stated.

The Installer tool is a command-line utility that allows you to install and uninstall server resources by executing the installer components in specified assemblies. This tool works in conjunction with classes in the System.Configuration.Install namespace.

This is no different from using the installer, as far as getting the service setup.

How to install a .NET windows service without InstallUtil.exe vb.net

Installutil is necessary, but to make things easier, you can create a Setup project, so that you simply run an .msi to install the service. (This uses installutil under the hood, but it greatly simplifies installation.)

One walkthrough is here: http://support.microsoft.com/kb/816169

And another is here: http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx

The main difference between the two is the amount of code in the samples. They both walk you throuigh the same process.

The articles linked to are old, but still apply in VS2010. I used the second article to walk through the process for a VS2010 service just last week.

How do I install a C# Windows service without creating an installer?

You can use installutil.

From the command line:

installutil YourWinService.exe

This utility is installed with the .NET Framework

Install a Windows service using a Windows command prompt?

Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe"

Regarding a comment, for 64bit apps, use below:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

installing windows service with SC.exe or InstallUtil.exe - there is difference but which?

Yes, installing a service isn't particularly complicated. It just takes writing a handful of registry keys. You can have a look-see with Regedit.exe, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services.

Sc.exe can write these keys too, using the supplied command line arguments. Nevertheless, this is not the right way to do it. The point of InstallUtil.exe is that it can activate custom installation code. Code that the service author wrote. Which is not that uncommon, services tend to stuff config info in their registration keys for their own use. You'll see plenty of evidence for that when you have a look with Regedit.

Windows Service without [RunInstaller]

I wrote a blog article about this 4 years ago:

MSI vs .NET

Basically the expert level answer is that Installer class custom actions are an evil antipattern invented by the .NET community. They are an extension of the RegSvr32 pattern and doesn't fit with the MSI table driven declarative design and shouldn't be used.

The Service Control Manager is an unmanaged API ( Advapi32.dll ) that pre-dates the .NET framework. Windows Installer already had excellent support in the 1990's for the SCM before .NET came along. Then .NET came along to create a pattern for writing managed services and while the ability to inherit from ServiceBase to get most of the plumbing for free is a good thing, the use of InstalUtil is not.

BTW you should also drop to DOS and check out the SC command. This will allow you to do all sorts of service installation actions in case you need to do something in the development environment without running an MSI.

Any way to override .NET Windows Service Name without recompiling?

Do you have to use InstallUtil? Here are the commands to do what you want using sc:

sc create MyService binPath= "MyService.exe" DisplayName= "MyService"  
sc description MyService "My description"

Reference: http://support.microsoft.com/kb/251192



Related Topics



Leave a reply



Submit