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.


I prefer sc.exe over installutil.exe.

InstallUtil forces you to add the dreadful ProjectInstaller class (I believe) and hardcode there the service name and service description.

InstallUtil makes it very hard to put two versions of the same service running in the same machine at the same time.

That's why I just don't use InstallUtil.exe at all. Also because of previous responses: you need it to be in your deploy package. sc.exe is already in any Windows Xp and above (I believe).


Main difference is that InstallUtil is not utility meant for service installation but as general installer tool. From MSDN pages you can see that:

"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."

So it can install service but it has many many many other benefits. Creating executables based on Installer Class gives you programatic control of whole installation/uninstallation procedure. ServiceInstaller and ServiceProcessInstaller, for instance, are used for service installation.

'Sc' utility is used for service control and 'create' command will just create service based on chosen executable.

In your example
1. It is not meant to be installed with InstallUtil and error response should be quite clear about it.
2. InstallUtil fails because of a bug in installation code and using sc create will probably create a faulty service for you. Check into {exe_name}.InstallLog for details.