22

我正在尝试安装 Windows 服务。

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

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

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

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

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

我可以在 Visual Studio 之外运行服务没问题。

安装程序.cs

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

这是 Visual Studio 提供的默认安装程序。

4

2 回答 2

30

您需要将一些 Installer 对象添加到 Installers 集合中。此处的示例是您安装 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);
    }
}
于 2012-09-11T04:09:18.980 回答
0

以下 SO 问题具有类似的场景和答案,可能也与从 Google 搜索链接来到这里的人相关。

安装在 Visual Studio 中创建的 Windows 服务

于 2017-01-22T18:12:48.413 回答