用于Windows服务的Inno安装程序?
我有一个.Net Windows服务。我想创建一个安装程序来安装该Windows服务。用于Windows服务的Inno安装程序?
基本上,它必须做到以下几点:
- 包
installutil.exe
(需要它?) - 运行
installutil.exe
MyService.exe - 开始为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"
非常感谢!这工作像魔术。 再一次澄清。如何在Inno Script中运行像net start WinServ这样的命令? – devnull 2009-09-20 02:13:57
你可以试试'Filename:“net.exe”;参数:“启动WinServ”。如果它不起作用,你可以再添加一个switch --start到你的c#应用程序,并通过使用ServiceController类直接从程序启动windows服务(http://msdn.microsoft.com/en-us/library/ system.serviceprocess.servicecontroller.aspx)。 – 2009-09-20 02:52:42
是的,太工作了! - 启动ServiceController类。 再次感谢! – devnull 2009-09-20 03:14:13
如果你想避免重新启动时的用户升级,那么你需要复制EXE之前停止服务之后再次启动。
有一些脚本的功能要做到这一点,在Service - Functions to Start, Stop, Install, Remove a Service
在你的链接文章中,所使用函数的原型没有被精确地翻译,它们的用法也不正确(例如,没有等待服务启动,停止等等。)。 – TLama 2014-12-11 05:27:20
您可以使用
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”,停止检查服务状态,删除服务等
我是这样做的:
Exec(ExpandConstant('{dotnet40}\InstallUtil.exe'), ServiceLocation, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
显然,创新安装有以下常量参考你的系统上的.NET文件夹:
- {} dotnet11
- {} dotnet20
- {} dotnet2032
- {dotnet2064}
- {dotnet40}
- {dotnet4032}
- {dotnet4064}可用here
的更多信息。
我想你需要使用[Run]部分。看[这里](http://www.vincenzo.net/isxkb/index.php?title = Inno_Setup_Help _-_'Run'_and_'UninstallRun'_sections) – 2009-09-20 01:16:20