Inno Setup的为Windows服务? [英] Inno Setup for Windows service?

查看:204
本文介绍了Inno Setup的为Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net Windows服务。我想创建一个安装程序来安装Windows服务。

I have a .Net Windows service. I want to create an installer to install that windows service.

基本上它有做到以下几点:

Basically it has to do the following:


  1. installutil.exe (需要它?)

  2. 运行 installutil.exe MyService.exe

  3. 开始为MyService

  1. Pack installutil.exe (Is it required?)
  2. Run installutil.exe MyService.exe
  3. Start MyService

另外,我想提供它运行以下命令卸载程序:

Also, I want to provide an uninstaller which runs the following command:

installutil.exe /u MyService.exe

如何做到这些使用Inno Setup的?

How to do these using Inno Setup?

推荐答案

您不需要 installutil.exe ,也许你甚至没有权利再分发

You don't need installutil.exe and probably you don't even have rights to redistribute it.

下面是我在做这在我的应用程序的方式:

Here is the way I'm doing it in my application:

using System;
using System.Collections.Generic;
using System.Configuration.Install; 
using System.IO;
using System.Linq;
using System.Reflection; 
using System.ServiceProcess;
using System.Text;

static void Main(string[] args)
{
    if (System.Environment.UserInteractive)
    {
        string parameter = string.Concat(args);
        switch (parameter)
        {
            case "--install":
                ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                break;
            case "--uninstall":
                ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                break;
        }
    }
    else
    {
        ServiceBase.Run(new WindowsService());
    }
}

基本上,你可以有你的服务,通过使用<一个自身的安装/卸载href=\"http://msdn.microsoft.com/en-us/library/system.configuration.install.managedinstallerclass.aspx\"><$c$c>ManagedInstallerClass如在我的例子。

Basically you can have your service to install/uninstall on its own by using ManagedInstallerClass as shown in my example.

然后,它只是物质添加到您的InnoSetup脚本是这样的:

Then it's just matter of adding into your InnoSetup script something like this:

[Run]
Filename: "{app}\MYSERVICE.EXE"; Parameters: "--install"

[UninstallRun]
Filename: "{app}\MYSERVICE.EXE"; Parameters: "--uninstall"

这篇关于Inno Setup的为Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆