Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install windows service without InstallUtil.exe

I'm trying to deploy a windows service but not quite sure how to do it right. I built it as a console app to start with, I've now turned it into a windows service project and just call my class from the OnStart method in the service.

I now need to install this on a server which doesn't have Visual Studio on it, which if I've understood it correctly means I can't use the InstallUtil.exe and have to create an installer class instead. Is this correct?

I did have a look at a previous question, Install a .NET windows service without InstallUtil.exe, but I just want to make sure I've understood it correctly.

If I create the class that question's accepted answer links to, what is the next step? Upload MyService.exe and MyService.exe.config to the server, double click the exe file and Bob's my uncle?

The service will only ever be installed on one server.

like image 582
annelie Avatar asked May 18 '10 11:05

annelie


People also ask

How do I remove a service using InstallUtil exe?

Uninstall using InstallUtil.exe utilityFrom the Start menu, select the Visual Studio <version> directory, then select Developer Command Prompt for VS <version>. The Developer Command Prompt for Visual Studio appears. After the executable for a service is deleted, the service might still be present in the registry.

What is InstallUtil exe?

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 tool is automatically installed with Visual Studio.

Where is InstallUtil exe located?

The InstallUtil binary may also be digitally signed by Microsoft and located in the . NET directories on a Windows system: C:\Windows\Microsoft.NET\Framework\v \InstallUtil.exe and C:\Windows\Microsoft.NET\Framework64\v \InstallUtil.exe .


2 Answers

I know it is a very old question, but better update it with new information.

You can install service by using sc command:

InstallService.bat:

@echo OFF echo Stopping old service version... net stop "[YOUR SERVICE NAME]" echo Uninstalling old service version... sc delete "[YOUR SERVICE NAME]"  echo Installing service... rem DO NOT remove the space after "binpath="! sc create "[YOUR SERVICE NAME]" binpath= "[PATH_TO_YOUR_SERVICE_EXE]" start= auto echo Starting server complete pause 

With SC, you can do a lot more things as well: uninstalling the old service (if you already installed it before), checking if service with same name exists... even set your service to autostart.

One of many references: creating a service with sc.exe; how to pass in context parameters

I have done by both this way & InstallUtil. Personally I feel that using SC is cleaner and better for your health.

like image 124
Hoàng Long Avatar answered Sep 29 '22 15:09

Hoàng Long


You can still use installutil without visual studio, it is included with the .net framework

On your server, open a command prompt as administrator then:

CD C:\Windows\Microsoft.NET\Framework\v4.0.version (insert your version)  installutil "C:\Program Files\YourWindowsService\YourWindowsService.exe" (insert your service name/location) 

To uninstall:

installutil /u "C:\Program Files\YourWindowsService\YourWindowsService.exe" (insert your service name/location) 
like image 35
George Filippakos Avatar answered Sep 29 '22 16:09

George Filippakos