我已阅读此问题Inno Setup for Windows service?。我有同样的问题,但我不明白从lubos hasko的答案。我该如何做到这一点?你有人可以发布我完整的演练吗?在.NET中自行安装windows服务c#
当我运行下面的代码时,会安装一些东西,但在服务列表中,我找不到它。 我有这个,但是这不工作:
using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
public class Service1 : ServiceBase
{
public Service1()
{
File.AppendAllText("sss.txt", "ccccc");
}
protected override void OnStart(string[] args)
{
File.AppendAllText("sss.txt", "asdfasdf");
}
protected override void OnStop()
{
File.AppendAllText("sss.txt", "bbbbb");
}
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 Service1());
}
Console.ReadKey();
}
}
}
我不understad这两种:
if (System.Environment.UserInteractive) ...
谢谢,那篇文章真的帮了我。但在文章中,作者使用了installutil。我不想使用installutil。有什么选择吗?答案是在这篇文章http://stackoverflow.com/questions/1449994/inno-setup-for-windows-service/1450051#1450051但我不知道如何使用它。 – Simon 2010-11-10 13:47:29
为什么你不想用installutil安装服务?如果是因为权限,您将无法在没有管理员权限的情况下安装服务。这没有工作。 – jlafay 2010-11-10 14:09:09
其实,我仍然使用installutil,但是通过ManagedInstallerClass.InstallHelper。这才是重点。当我部署我的程序时,我也不需要部署installutil.exe。在使用Inno Setup安装应用程序期间安装WS,这是在管理员权限下进行的,因此没有问题... – Simon 2010-11-11 09:45:01