Cannot install windows service
Asked Answered
M

13

80

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.

Masturbation answered 10/11, 2010 at 9:18 Comment(2)
Wait... doesn't .NET 4 already include .NET 2/3/3.5?Periodicity
Yes, the service with all frameworks installed for another purpose, i was just illusrating the problem seems to be domain related.Masturbation
A
-3

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

Amati answered 10/11, 2010 at 9:50 Comment(7)
This is more a workaround than a real solution to the problemAsafoetida
see the up-voted answer below which should really be marked as the solutionBuffer
This feature doesn't exist in VS 2013Zoroastrian
@Zoroastrian it does work in VS 2013, you'll have to install it from here visualstudiogallery.msdn.microsoft.com/…Amati
@Buffer - life saving advice right there and also a reminder to keep scrolling on SO posts :)Lassiter
Before creating a setup project, you should consider unblocking the files (as explained in https://mcmap.net/q/258942/-cannot-install-windows-service)Raceway
@StefanP. It is really troublesome to create a setup project compared to simply unblocking it...Lazes
C
292

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.

Cerussite answered 9/3, 2011 at 12:44 Comment(7)
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.Mb
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.Piste
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 :)Cerussite
Remember and unblock any associated DLLs as well as the main exe folksMetronymic
Unblocking the individual files didn't work for me. I had to unblock the zip file I downloaded them in.Zoroastrian
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.Bauble
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.Dubois
G
21

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)
Granger answered 22/7, 2016 at 3:51 Comment(2)
Or simply get-childitem "C:\MyFolder" | unblock-fileRiven
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.Individuation
C
14

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.

Chane answered 21/2, 2017 at 14:36 Comment(0)
H
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.

Helainehelali answered 2/2, 2012 at 1:40 Comment(2)
Based on question #8524923 One could also set the runtime loadFromRemoteSources element to true in the machine.config.Commodity
I had to go to the properties of every file and "Unblock" the file.Fluff
B
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...

Bertelli answered 10/11, 2010 at 10:4 Comment(2)
The result of that is [SC] CreateService SUCCESS but the service still cannot be started. It complains it cannot find the specified file.Masturbation
I added full network share trust also. Still it says cannot find the specified file.Katricekatrina
E
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.

Eucaine answered 31/1, 2012 at 20:18 Comment(0)
B
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

Backplate answered 13/6, 2012 at 10:37 Comment(0)
K
1

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.

Kitts answered 25/9, 2014 at 17:12 Comment(0)
O
1

you can use this command in developer command prompt run administrator

installutil C:\...\MyService\bin\Debug\MyService.exe
Overdrive answered 2/8, 2016 at 12:53 Comment(1)
That is what he already does and it doesn't solve his problem.Akimbo
C
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).

Caulescent answered 5/9, 2012 at 10:52 Comment(0)
E
0

Simply right click on your service files and select properties and then check the unblock checkbox

https://brianseekford.azurewebsites.net/2011/07/13/hresult-0x80131515-when-running-installutil-to-install-a-net-service/

Eyas answered 3/1, 2022 at 2:49 Comment(0)
S
0

Unblocking files did the job here. Weird thing is that the blocked files came from a signed installer run with admin privileges. Had to unblock several files in several folders at once.

I used the following registry tweaks to add context menus to a folder or file when Shift + right-click is pressed (it doesn't show up if just right-clicked).

Credits and references to the author in each code block.

Folder tweak:

Just save it as ShiftUnblockFolder.reg and import into Registry.

Windows Registry Editor Version 5.00

; Created by: Shawn Brink
; Created on: March 17th 2019
; Tutorial: https://www.tenforums.com/tutorials/129101-add-unblock-file-context-menu-windows-10-a.html

[HKCR\Directory\shell\unblock]
"MUIVerb"="Unblock"
"Extended"=""
"SubCommands"=""

[HKCR\Directory\shell\unblock\shell\001flyout]
"MUIVerb"="Unblock files only in this folder"

[HKCR\Directory\shell\unblock\shell\001flyout\command]
@="powershell.exe get-childitem -LiteralPath '%L' | Unblock-File"

[HKCR\Directory\shell\unblock\shell\002flyout]
"MUIVerb"="Unblock files in this folder and subfolders"

[HKCR\Directory\shell\unblock\shell\002flyout\command]
@="powershell.exe get-childitem -LiteralPath '%L' -recurse | Unblock-File"

Single file tweak:

ShiftUnblockFile.reg

Windows Registry Editor Version 5.00

; Created by: Shawn Brink
; Created on: March 17th 2019
; Tutorial: https://www.tenforums.com/tutorials/129101-add-unblock-file-context-menu-windows-10-a.html

[HKCR\*\shell\unblock]
"MUIVerb"="Unblock"
"Extended"=""

[HKCR\*\shell\unblock\command]
@="powershell.exe Unblock-File -LiteralPath '%L'"

[HKCR\Directory\shell\unblock]
"MUIVerb"="Unblock"
"Extended"=""
"SubCommands"=""

[HKCR\Directory\shell\unblock\shell\001flyout]
"MUIVerb"="Unblock files only in this folder"

[HKCR\Directory\shell\unblock\shell\001flyout\command]
@="powershell.exe get-childitem -LiteralPath '%L' | Unblock-File"

[HKCR\Directory\shell\unblock\shell\002flyout]
"MUIVerb"="Unblock files in this folder and subfolders"

[HKCR\Directory\shell\unblock\shell\002flyout\command]
@="powershell.exe get-childitem -LiteralPath '%L' -recurse | Unblock-File"
Stickweed answered 16/5, 2022 at 13:38 Comment(0)
A
-3

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

Amati answered 10/11, 2010 at 9:50 Comment(7)
This is more a workaround than a real solution to the problemAsafoetida
see the up-voted answer below which should really be marked as the solutionBuffer
This feature doesn't exist in VS 2013Zoroastrian
@Zoroastrian it does work in VS 2013, you'll have to install it from here visualstudiogallery.msdn.microsoft.com/…Amati
@Buffer - life saving advice right there and also a reminder to keep scrolling on SO posts :)Lassiter
Before creating a setup project, you should consider unblocking the files (as explained in https://mcmap.net/q/258942/-cannot-install-windows-service)Raceway
@StefanP. It is really troublesome to create a setup project compared to simply unblocking it...Lazes

© 2022 - 2024 — McMap. All rights reserved.