Cannot install windows service

56,621

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.

Share:
56,621

Related videos on Youtube

Matthew Dalton
Author by

Matthew Dalton

Updated on July 05, 2022

Comments

  • Matthew Dalton
    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
      Camilo Martin over 13 years
      Wait... doesn't .NET 4 already include .NET 2/3/3.5?
    • Matthew Dalton
      Matthew Dalton over 13 years
      Yes, the service with all frameworks installed for another purpose, i was just illusrating the problem seems to be domain related.
  • Matthew Dalton
    Matthew Dalton over 13 years
    The result of that is [SC] CreateService SUCCESS but the service still cannot be started. It complains it cannot find the specified file.
  • MKing
    MKing about 13 years
    This 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
    Ross Hambrick over 12 years
    Thank 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
    Snives about 12 years
    If 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
    Scratz over 11 years
    Based on question stackoverflow.com/questions/8524423/… One could also set the runtime loadFromRemoteSources element to true in the machine.config.
  • doublehelix
    doublehelix over 11 years
    Another 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
    Srikanth P Vasist almost 11 years
    I added full network share trust also. Still it says cannot find the specified file.
  • thepirat000
    thepirat000 over 10 years
    This is more a workaround than a real solution to the problem
  • c00000fd
    c00000fd over 10 years
    Jeez, this was the easiest fix! Thanks.
  • Alan Macdonald
    Alan Macdonald over 10 years
    Remember and unblock any associated DLLs as well as the main exe folks
  • user1282609
    user1282609 almost 10 years
    What a great solution. Thank you so much.
  • Andy
    Andy over 9 years
    see the up-voted answer below which should really be marked as the solution
  • cja
    cja over 9 years
    This feature doesn't exist in VS 2013
  • cja
    cja over 9 years
    Unblocking the individual files didn't work for me. I had to unblock the zip file I downloaded them in.
  • Stefan P.
    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
    Andrew - OpenGeoCode almost 9 years
    Thanks, once again stackoverflow to the rescue - worked for me
  • Omni
    Omni over 8 years
    Thanks for remind me of that, avoided minutes of frustration
  • Rumit Parakhiya
    Rumit Parakhiya about 8 years
    Just 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
    ohager over 7 years
    YMMD - I lost one year of my life until this helped me out!
  • Trevor Daniel
    Trevor Daniel over 7 years
    I had to go to the properties of every file and "Unblock" the file.
  • Tommy
    Tommy over 7 years
    @Andy - life saving advice right there and also a reminder to keep scrolling on SO posts :)
  • Peet Brits
    Peet Brits about 7 years
    Or simply get-childitem "C:\MyFolder" | unblock-file
  • Mike W
    Mike W about 7 years
    has 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
    Sascha over 6 years
    That is what he already does and it doesn't solve his problem.
  • Volkmar Rigo
    Volkmar Rigo over 6 years
    Before creating a setup project, you should consider unblocking the files (as explained in stackoverflow.com/a/5245971/597028)
  • cdhowie
    cdhowie about 6 years
    If 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
    Felipe Oriani about 6 years
    2018 and still have this problem. Thank you!
  • Chromium
    Chromium almost 6 years
    @StefanP. It is really troublesome to create a setup project compared to simply unblocking it...