我已閱讀此問題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