How To Install Windows Service Without Installutil Exe

  1. Windows Installutil Location
  2. Install Windows Service.net
  3. Install Windows Service Using Installutil
  4. How To Install Windows Service Without Installutil Exempt
  5. Register Windows Service

I have a standard .NET windows service written in C#.

Install windows service c# without installutil - How to install a windows service programmatically in C#? 4 Answers Ok, here is what REALLY worked for me, it has been tested on multiple machines with different OS ( Vista, XP, Win2k, Win2003 server ).

How to install windows service pack 1

Can it install itself without using InstallUtil?
Should I use the service installer class? How should I use it?

I want to be able to call the following:

MyService.exe -install

and it will have the same effect as calling:

InstallUtil MyService.exe

Answers:

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.

Answers:

Take a look at the InstallHelper method of the ManagedInstaller class. You can install a service using:

This is exactly what InstallUtil does. The arguments are the same as for InstallUtil.

The benefits of this method are that it involves no messing in the registry, and it uses the same mechanism as InstallUtil.

Answers:

You can always fall back to the good old WinAPI calls, although the amount of work involved is non-trivial. There is no requirement that .NET services be installed via a .NET-aware mechanism.

To install:

  • Open the service manager via OpenSCManager.
  • Call CreateService to register the service.
  • Optionally call ChangeServiceConfig2 to set a description.
  • Close the service and service manager handles with CloseServiceHandle.

To uninstall:

  • Open the service manager via OpenSCManager.
  • Open the service using OpenService.
  • Delete the service by calling DeleteService on the handle returned by OpenService.
  • Close the service and service manager handles with CloseServiceHandle.

The main reason I prefer this over using the ServiceInstaller/ServiceProcessInstaller is that you can register the service with your own custom command line arguments. For example, you might register it as 'MyApp.exe -service', then if the user runs your app without any arguments you could offer them a UI to install/remove the service.

Running Reflector on ServiceInstaller can fill in the details missing from this brief explanation.

P.S. Clearly this won’t have “the same effect as calling: InstallUtil MyService.exe” – in particular, you won’t be able to uninstall using InstallUtil. But it seems that perhaps this wasn’t an actual stringent requirement for you.

Answers:

Here is a class I use when writing services. I usually have an interactive screen that comes up when the service is not called. From there I use the class as needed. It allows for multiple named instances on the same machine -hence the InstanceID field

Sample Call

The class itself

Answers:

The above examples didn’t really work for me, and the link to the forum as a #1 solution is aweful to dig through. Here is a class I wrote (in part), and the other bit is merged from this link I found buried somewhere

To install a service, run the InstallAndStart command as follows:

Make sure the account that is running the program has permission to install services. You can always ‘Run As Administrator’ on the program.

I have also included several commands for non-api access which do not install or remove services, but you can list them and control several (start, stop, restart). You really only need to elevate permissions for installing or removing services.

There are a couple of commands for getting and setting environment variables as well, such as OPENSSL_CONF or TEMP. For the most part, the parameters and method names should be pretty self-explanatory.

Windows
Answers:

In the case of trying to install a command line application as a Windows service try the ‘NSSM‘ utility. Related ServerFault details found here.

Answers:
How To Install Windows Service Without Installutil Exe

Process QProc = new Process();

QProc.StartInfo.FileName = “cmd”;

Windows Installutil Location

QProc.StartInfo.Arguments =”/c InstallUtil “+ “””+ filefullPath +”””;

QProc.StartInfo.WorkingDirectory = Environment.GetEnvironmentVariable(“windir”) + @”Microsoft.NETFrameworkv2.0.50727”;

Tags: .net, service, windows

Active7 years, 7 months ago

I have created a windows service in vb.net. Is there anyway i can create an installation for it that does not require installutil to be used?

SimonSimon

3 Answers

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

Install Windows Service.net

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.

Install Windows Service Using Installutil

DavidDavid
63k13 gold badges119 silver badges160 bronze badges

Why do you want to avoid installutils?

How To Install Windows Service Without Installutil Exempt

You could try using the sc command, as in sc create ...

EDIT: Here's an MSDN page for it: http://support.microsoft.com/?kbid=251192

Register Windows Service

jglouiejglouie
9,3474 gold badges38 silver badges57 bronze badges

You can always do it with registry entries.
The keys are found in HKLMSYSTEMCurrentControlSetservices

The key name you create is the embedded name of the service on your service handler. The following values are relevant:

DisplayName = text that gets displayed in the services manager

ImagePath = FQ Filename of service executable

Start (DWORD) = startup type (3 = autostart)

DelayedAutoStart (DWORD) = (1 = delayed)

WOW64 (DWORD) = (0 = 64-bit app, 1 = 32-bit app)

ErrorControl (DWORD) = 0

ObjectName = {username} to run under (LocalSystem for system account)

There are lots of other values, but that should get you started.

Matt Wilko
23.2k9 gold badges74 silver badges122 bronze badges
Robert BeaubienRobert Beaubien
2,6663 gold badges16 silver badges25 bronze badges

Not the answer you're looking for? Browse other questions tagged .netvb.netservicewindows-servicesinstallutil or ask your own question.