Cannot install windows service

77

I have created a very simple window service using visual studio 2010 and .NُET 4.0.

This service has no functionality added from the default windows service project, other than an installer has been added.

If I run "installutil.exe appName.exe" on my dev box or other windows 2008 R2 machines in our domain the windows service installs without issue.

When I try to do this same thing on our customer site, it fails to install with the following error.

Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\TestService\WindowsService1.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515).

This solution has only 1 project and no dependencies added.

I have tried it on multiple machines in our environment and two in our customers. The machines are all windows 2008 R2, both fresh installs. One machine has just .net 2.0 and .net 4.0. The other .net 2, 3, 3.5 and 4.

I am a local admin on each of the machines.

I have also tried the 64bit installer but get the following error, so I think the 32 bit one is the one to use. System.BadImageFormatException

Any guidance would be appreciated. Thanks.

c#
windows-services
.net-4.0
installutil
asked on Stack Overflow Nov 10, 2010 by Matthew Dalton • edited May 19, 2017 by Hakan Fıstık

11 Answers

286

Another reason for this error might be that you copied your program from a source which windows considers untrusted. You can unblock the assembly by clicking "unblock" after you right-click and select properties on the file.

answered on Stack Overflow Mar 9, 2011 by doublehelix
18

Need to unblock files. or at least that's what fixed mine.

To do 'bulk' unblock in Powershell

get-childitem *.* | Unblock-File 

or in DOS:

FOR %a in (*.*) do (echo.>%a:Zone.Identifier)
answered on Stack Overflow Jul 22, 2016 by OzBob
12

When we copy executable from another computer, Windows mark a flag on them for protection. Right Click on executable and in properties Click Unblock. It would clear flag and service executable would Install.

answered on Stack Overflow Feb 21, 2017 by Sanjay Sharma
10

This issue came about for me because I was trying to install the service from a network location. By copying the service.exe to the local machine prior to using installutil, it fixed my problem and the service installed successfully.

answered on Stack Overflow Feb 2, 2012 by Brandon Ward
2

don't forget to vote up... Try the SC as follows: 1. open command line 2. write the below- sc create ServiceName BinPath= "ExePath". report on results...

answered on Stack Overflow Nov 10, 2010 by user437631
1

I also faced the same issue. In my case I was deploying new version of utilities , i copied new exe , installog files and then trying to uninstall the utils.

I copied back the old version , uninstal the utils , copied the new version and installed it again. Anyway it is the logical sequence I should have followed in first place.

answered on Stack Overflow Jan 31, 2012 by OnceBitten
1

i have this issue and it for different between of .net version of util and my service
i use util for .net 2 and my service build with .net4

answered on Stack Overflow Jun 13, 2012 by Saeed-rz
1

you can use this command in developer command prompt run administrator

installutil C:\...\MyService\bin\Debug\MyService.exe
answered on Stack Overflow Aug 2, 2016 by Oguzhan KIRCALI
0

As per @doublehelix's response above, this answer put me on track for my particular issue which related to a service issue running in Windows XP (Unblock is not an option in the security tab that I could find). In my case I was attempting to run a service from a separate drive (i.e. not on the same drive as Windows and not under program files) although the actual physical disk was the same. Moving my service into the Program Files folder solved my underlying issue. (I intended to 'comment' against @doublehelix's answer but I don't seem to be able to in my current status).

answered on Stack Overflow Sep 5, 2012 by The Senator • edited Jan 3, 2015 by doublehelix
0

In my case this error was caused by accidentally passing the directory containing the service to InstallUtil instead of passing the service exe.

Obviously human error but I found the error message quite misleading.

answered on Stack Overflow Sep 25, 2014 by Lawrence Johnston
-2

You can try to make a Setup Project for your service and run the MSI file on that server.

answered on Stack Overflow Nov 10, 2010 by Stefan P.

User contributions licensed under CC BY-SA 3.0