Inno Setup for Windows 서비스? 해당 Windows 서비스를 설치하기

.Net Windows 서비스가 있습니다. 해당 Windows 서비스를 설치하기 위해 설치 프로그램을 만들고 싶습니다.

기본적으로 다음을 수행해야합니다.

  1. installutil.exe(필수입니까?)
  2. installutil.exeMyService.exe 실행
  3. MyService 시작

또한 다음 명령을 실행하는 제거 프로그램을 제공하고 싶습니다.

installutil.exe /u MyService.exe

Inno Setup을 사용하여 어떻게하나요?



답변

필요 installutil.exe하지 않으며 재배포 할 권한도 없을 것입니다.

내 응용 프로그램에서 수행하는 방법은 다음과 같습니다.

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());
    }
}

기본적으로 ManagedInstallerClass내 예제와 같이 사용하여 서비스를 자체적으로 설치 / 제거 할 수 있습니다 .

그런 다음 다음과 같이 InnoSetup 스크립트에 추가하면됩니다.

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

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

답변

내가 한 방법은 다음과 같습니다.

Exec(ExpandConstant('{dotnet40}\InstallUtil.exe'), ServiceLocation, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);

분명히 Inno 설정에는 시스템의 .NET 폴더를 참조하기위한 다음 상수가 있습니다.

  • {dotnet11}
  • {dotnet20}
  • {dotnet2032}
  • {dotnet2064}
  • {dotnet40}
  • {dotnet4032}
  • {dotnet4064}

여기에서 자세한 정보를 확인할 수 있습니다 .


답변

당신이 사용할 수있는

Exec(
    ExpandConstant('{sys}\sc.exe'),
    ExpandConstant('create "MyService" binPath= {app}\MyService.exe start= auto DisplayName= "My Service" obj= LocalSystem'),
    '',
    SW_HIDE,
    ewWaitUntilTerminated,
    ResultCode
    )

서비스를 생성합니다. 시작, 중지, 서비스 상태 확인, 서비스 삭제 등에 대해서는 ” sc.exe “를 참조하십시오 .


답변

사용자가 업그레이드 할 때 재부팅을 방지하려면 exe를 복사하기 전에 서비스를 중지하고 이후에 다시 시작해야합니다.

서비스 에서이 작업을 수행하는 몇 가지 스크립트 기능이 있습니다 -서비스 시작, 중지, 설치, 제거 기능