C# 无法借助 InstallUtil 工具安装 windows 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15009163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:46:37  来源:igfitidea点击:

Unable to install windows service with the help of InstallUtil tool

c#.netwindows-services

提问by Aleksei Chepovoi

I use VS 2012 and since the setup projects have been removed from it I have to use InstallUtil.exe.

我使用 VS 2012,并且由于安装项目已从中删除,因此我必须使用 InstallUtil.exe。

I don't have projectInstaller class in my windows service app. I run in command prompt:

我的 Windows 服务应用程序中没有 projectInstaller 类。我在命令提示符下运行:

installutil FilesMonitoringService.exe 

I get:

我得到:

C:\Program Files\Microsoft Visual Studio 8\VC#>installutil "C:\Program Files\Mic rosoft Visual Studio 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyServ ice.exe" Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved.

Running a transacted installation.

Beginning the Install phase of the installation. See the contents of the log file for the C:\Program Files\Microsoft Visual Studi o 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProj ects\MyService\MyService\bin\Release\MyService.InstallLog. Installing assembly 'C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjec ts\MyService\MyService\bin\Release\MyService.exe'. Affected parameters are: logtoconsole = assemblypath = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\ MyService\MyService\bin\Release\MyService.exe logfile = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MySer vice\MyService\bin\Release\MyService.InstallLog No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MyService\ MyService\bin\Release\MyService.exe assembly.

The Install phase completed successfully, and the Commit phase is beginning. See the contents of the log file for the C:\Program Files\Microsoft Visual Studi o 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProj ects\MyService\MyService\bin\Release\MyService.InstallLog. Committing assembly 'C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjec ts\MyService\MyService\bin\Release\MyService.exe'. Affected parameters are: logtoconsole = assemblypath = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\ MyService\MyService\bin\Release\MyService.exe logfile = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MySer vice\MyService\bin\Release\MyService.InstallLog No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MyService\ MyService\bin\Release\MyService.exe assembly. Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

C:\Program Files\Microsoft Visual Studio 8\VC#>

C:\Program Files\Microsoft Visual Studio 8\VC#>installutil "C:\Program Files\Mic rosoft Visual Studio 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyServ ice.exe" Microsoft (R) .NET Framework 安装实用程序版本 2.0.50727.42 版权所有 (c) Microsoft Corporation。版权所有。

运行事务安装。

开始安装的安装阶段。查看 C:\Program Files\Microsoft Visual Studi o 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.exe 程序集进度的日志文件的内容。该文件位于 C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.InstallLog。安装程序集“C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjec ts\MyService\MyService\bin\Release\MyService.exe”。受影响的参数是: logtoconsole = assemblypath = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\ MyService\MyService\bin\Release\MyService.exe logfile = C:\Program Files\Microsoft Visual Studio 8\VC# \CSharpProjects\MyService\MyService\bin\Release\MyService。

安装阶段成功完成,提交阶段开始。查看 C:\Program Files\Microsoft Visual Studi o 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.exe 程序集进度的日志文件的内容。该文件位于 C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MyService\MyService\bin\Release\MyService.InstallLog。提交程序集“C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjec ts\MyService\MyService\bin\Release\MyService.exe”。受影响的参数是: logtoconsole = assemblypath = C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\ MyService\MyService\bin\Release\MyService.exe logfile = C:\Program Files\Microsoft Visual Studio 8\VC# \CSharpProjects\MyService\MyService\bin\Release\MyService。InstallLog 在 C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MyService\ MyService\bin\Release\MyService.exe 程序集中找不到具有 RunInstallerAttribute.Yes 属性的公共安装程序。删除 InstallState 文件,因为没有安装程序。

提交阶段成功完成。

事务安装已完成。

C:\Program Files\Microsoft Visual Studio 8\VC#>

OK, seems like everything have been installed. But! When I go to task manager to the Services page I can't find my service.

好的,似乎一切都已安装。但!当我转到任务管理器的“服务”页面时,我找不到我的服务。

What could be the reason?

可能是什么原因?

Thanks in advance!

提前致谢!

Edits:I pointed out that I don't have projectInstaller class because if I add it (in designer -> add installer) and run installutil command I get: (approximate translation)

编辑:我指出我没有 projectInstaller 类,因为如果我添加它(在设计器中 -> 添加安装程序)并运行 installutil 命令我得到:(近似翻译)

Installation of FilesMonitoringService... Creation of EventLog FilesMonitoringService in a log jornal Application...

安装 FilesMonitoringService... 在日志应用程序中创建 EventLog FilesMonitoringService...

On this setup stage the exception occured.

在这个设置阶段发生了异常。

System.Security.SecurityException: The source is not found, but failed to find by any or all log jornals. Not available jornals: Security.

The recoil stage starts.

// lots of text

The recoil stage has succeded

Setup group operation executed. Setup failed and recoil was executed.

System.Security.SecurityException:未找到源,但任何或所有日志日志都无法找到源。不可用的期刊:安全。

后坐力阶段开始。

// 大量文字

后坐力阶段成功

已执行设置组操作。安装失败并执行反冲。

So, if I add projectInstller to my windows service it definitely fails to install with installUtil.
Here is the generated code:

因此,如果我将 projectInstller 添加到我的 Windows 服务中,它肯定无法使用 installUtil 进行安装。
这是生成的代码:

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
    }
    private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
    {}
    private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
    {}
}

Mabby I need to put some code into afterInstall methods? I also set this properies in a propertieswindow:

Mabby 我需要将一些代码放入 afterInstall 方法中吗?我还在一个properties窗口中设置了这个属性:

serviceInstaller1: ServiceName -> FileMonitoringService, StartType -> Automatic
serviceProcessInstaller1: Account -> LocalSystem

serviceInstaller1: ServiceName -> FileMonitoringService, StartType -> Automatic
serviceProcessInstaller1: Account -> LocalSystem

Or can it be implemented without projectInstaller?

或者可以在没有projectInstaller的情况下实现吗?

采纳答案by Aleksei Chepovoi

Ok, there are couple of things:

好的,有几件事:

1) You need projectInstaller.
2) YourProject -> properties; Startup project -> YourProject.Program
3) build
4) “Run as Administrator” the command prompt!

1)你需要projectInstaller。
2) 你的项目 -> 属性;启动项目 -> YourProject.Program
3) build
4) “以管理员身份运行”命令提示符!

Everything works now.

现在一切正常。

complete tutorial link

完整教程链接

回答by Gama Felix

I don't have a copy of VS2012 to test it now, but I believe that your problem has something to do with the

我现在没有 VS2012 的副本来测试它,但我相信您的问题与

I don't have projectInstaller class in my windows service app

我的 Windows 服务应用程序中没有 projectInstaller 类

part.

部分。

From msdn:

msdn

Installation components register an individual service on the system to which it is being installed and let the Services Control Manager know that the service exists

安装组件在安装它的系统上注册单个服务,并让服务控制管理器知道该服务存在

回答by NahuelGQ

It seems trivial, but check carefully when you are writing the installutill arguments, because you could confuse the exe file of the service with another exe file generated by the compilation of a referenced project (that has no service installers) and make it fail.

这似乎微不足道,但在编写 installutill 参数时请仔细检查,因为您可能会将服务的 exe 文件与编译引用的项目(没有服务安装程序)生成的另一个 exe 文件混淆,并使其失败。