c# - installutil 成功完成但未安装服务

标签 c# windows-services

我正在尝试安装 Windows 服务。

运行 c:\windows\microsoft.net\Framework64\v4.0.30319\InstallUtil.exe c:\foo\MyAssembly.exe

我收到一条好消息,表明所有阶段(安装、提交)都已成功完成。

(我没有收到输入服务凭证的提示)

之后我在服务控制台中看不到该服务。安装日志中没有任何用处。

该解决方案是在 64 位机器上构建的,我正在尝试在 64 位机器上安装该服务。但是,我没有将 64 位视为解决方案属性中的一个选项。我确实手动编辑了所有 csproj 文件,为 [platform] 节点选择“x64”..

我可以毫无问题地在 visual studio 外运行该服务。

安装程序.cs

[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
    public Installer() {
        InitializeComponent();
    }
}

这是 visual studio 提供的默认安装程序。

最佳答案

您需要将一些 Installer 对象添加到 Installers 集合中。示例 here是安装 Windows 服务所需的。有点像

[RunInstaller(true)]
public class Installer : System.Configuration.Install.Installer
{
    private ServiceInstaller serviceInstaller;
    private ServiceProcessInstaller processInstaller;

    public Installer()
    {
        // Instantiate installers for process and services.
        processInstaller = new ServiceProcessInstaller();
        serviceInstaller = new ServiceInstaller();

        // The services run under the system account.
        processInstaller.Account = ServiceAccount.LocalSystem;

        // The services are started manually.
        serviceInstaller.StartType = ServiceStartMode.Manual;

        // ServiceName must equal those on ServiceBase derived classes.
        serviceInstaller.ServiceName = "Hello-World Service 1";

        // Add installers to collection. Order is not important.
        Installers.Add(serviceInstaller);
        Installers.Add(processInstaller);
    }
}

关于c# - installutil 成功完成但未安装服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12362455/

相关文章:

c# - 分布式窗口服务

c# - LINQ 不适用于 Xamarin 中的字符串?

c# - 如何清除内存流

c# - 将 System.Collections.Generic.SortedList<string,T> 转换为 IEnumerable<T>

c# - 这是使用 LINQ 创建频率表的最佳方式吗?

java - 当 apache tomcat 作为 Windows 服务安装时,如何配置 apache tomcat 使用不同的 java home?

c# - 将 C# 项目从 visual studio 2010 降级到 visual studio 2008

c# - 如何定位 exit() 调用的来源

c# - 在 Windows 服务中更改计时器间隔

visual-studio - 在visual studio中添加服务安装程序和服务进程安装程序