Cannot install windows service
Solution 1
You can try to make a Setup Project for your service and run the MSI file on that server.
Solution 2
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.
Solution 3
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)
Solution 4
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.
Solution 5
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.
Related videos on Youtube
Matthew Dalton
Updated on July 05, 2022Comments
-
Matthew Dalton almost 2 years
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.
-
Camilo Martin over 13 yearsWait... doesn't .NET 4 already include .NET 2/3/3.5?
-
Matthew Dalton over 13 yearsYes, the service with all frameworks installed for another purpose, i was just illusrating the problem seems to be domain related.
-
-
Matthew Dalton over 13 yearsThe result of that is [SC] CreateService SUCCESS but the service still cannot be started. It complains it cannot find the specified file.
-
MKing about 13 yearsThis worked for me and answers the question more directly than the, "try a Setup Project" answer. Both work, but this is more likely the answer to the original question.
-
Ross Hambrick over 12 yearsThank you! I doubt I would have ever made it to this conclusion. I wish it reported a better reason than "Operation is not supported"
-
Snives about 12 yearsIf it won't unblock and it resides in your /Program Files folder then move the .exe to your documents folder, unblock it there, and then move it back. Windows Explorer won't elevate unblock requests in the /Program Files folders.
-
Scratz over 11 yearsBased on question stackoverflow.com/questions/8524423/… One could also set the runtime
loadFromRemoteSources
element to true in the machine.config. -
doublehelix over 11 yearsAnother useful advice: If you unblock a zip file before extraction, then all extracted files are automatically unblocked. Can save you a lot of work of unblocking them one by one :)
-
Srikanth P Vasist almost 11 yearsI added full network share trust also. Still it says cannot find the specified file.
-
thepirat000 over 10 yearsThis is more a workaround than a real solution to the problem
-
c00000fd over 10 yearsJeez, this was the easiest fix! Thanks.
-
Alan Macdonald over 10 yearsRemember and unblock any associated DLLs as well as the main exe folks
-
user1282609 almost 10 yearsWhat a great solution. Thank you so much.
-
Andy over 9 yearssee the up-voted answer below which should really be marked as the solution
-
cja over 9 yearsThis feature doesn't exist in VS 2013
-
cja over 9 yearsUnblocking the individual files didn't work for me. I had to unblock the zip file I downloaded them in.
-
Stefan P. over 9 years@cja it does work in VS 2013, you'll have to install it from here visualstudiogallery.msdn.microsoft.com/…
-
Andrew - OpenGeoCode almost 9 yearsThanks, once again stackoverflow to the rescue - worked for me
-
Omni over 8 yearsThanks for remind me of that, avoided minutes of frustration
-
Rumit Parakhiya about 8 yearsJust in case somebody needs to do this and have lot of dlls and exe as dependency, you can use powershell command
Get-ChildItem | Unblock-File
in the directory where service executables are. It'll unblock all files. -
ohager over 7 yearsYMMD - I lost one year of my life until this helped me out!
-
Trevor Daniel over 7 yearsI had to go to the properties of every file and "Unblock" the file.
-
Tommy over 7 years@Andy - life saving advice right there and also a reminder to keep scrolling on SO posts :)
-
Peet Brits about 7 yearsOr simply
get-childitem "C:\MyFolder" | unblock-file
-
Mike W about 7 yearshas MS fixed their error message yet? Is anyone aware of an MS ticket open for this? The error message gives you no indication of how to fix the problem.
-
Sascha over 6 yearsThat is what he already does and it doesn't solve his problem.
-
Volkmar Rigo over 6 yearsBefore creating a setup project, you should consider unblocking the files (as explained in stackoverflow.com/a/5245971/597028)
-
cdhowie about 6 yearsIf the files are being transferred to another machine, another easy way to unblock them all at once is to zip up the files, copy over the zip file, unblock the zip file, then extract it. The extracted files will also be unblocked.
-
Felipe Oriani about 6 years2018 and still have this problem. Thank you!
-
Chromium almost 6 years@StefanP. It is really troublesome to create a setup project compared to simply unblocking it...