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

标签 c# .net windows-services

我使用 VS 2012,因为安装项目已从中删除,所以我必须使用 InstallUtil.exe。

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

installutil FilesMonitoringService.exe 

我得到:

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#>

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

可能是什么原因?

提前致谢!

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

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

在此设置阶段发生异常。

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.

因此,如果我将 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 我需要将一些代码放入 afterInstall 方法中吗?我还在 properties 窗口中设置了这个属性:

serviceInstaller1: ServiceName -> FileMonitoringService, StartType -> Automatic
serviceProcessInstaller1:帐户 -> 本地系统

或者不用projectInstaller也能实现吗?

最佳答案

好的,有两件事:

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

现在一切正常。

complete tutorial link

关于c# - 无法借助InstallUtil工具安装windows服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15009163/

相关文章:

c# - 如何记录查询时间?

c# - 在 Windows 服务中执行任务循环的最佳方法

C# - 当我使用 task::wait() 方法时它抛出异常

c# - 泛型类型的 UML 图?

c# - 在读取测试方法数据之前强制执行 ClassInitialize

java - 从 .NET 应用程序访问 Android 数据库

java - Windows 服务登录前访问网络

delphi - 在delphi中创建Windows服务

c# - 可选的构造函数

c# - 绑定(bind)到项目而不是列表框中的属性