我有一个.Net视窗服务。我想创建一个安装程序来安装那个windows服务。
基本上,它必须执行以下操作:
installutil.exe
(是否必需?) installutil.exe
MyService.exe <代码>G29
另外,我还想提供一个卸载程序,它可以运行以下命令:
installutil.exe /u MyService.exe
如何使用Inno设置来完成这些操作?
发布于 2009-09-20 01:39:52
你不需要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"
发布于 2014-10-16 17:53:56
下面是我是如何做到的:
Exec(ExpandConstant('{dotnet40}\InstallUtil.exe'), ServiceLocation, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
显然,Inno setup具有以下常量,用于引用系统上的.NET文件夹:
有关更多信息,请访问here。
发布于 2010-08-15 23:33:08
您可以使用
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。
https://stackoverflow.com/questions/1449994
复制相似问题