【发布时间】:2011-05-07 20:08:25
【问题描述】:
我已阅读this question。我有同样的问题,但我不明白 lubos hasko 的答案。我该怎么做?有人能发给我完整的演练吗?
当我运行下面的代码时,安装了一些东西,但在服务列表中,我找不到它。
我有这个,但这不起作用:
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();
}
}
}
我也不明白这个:
if (System.Environment.UserInteractive) ...
【问题讨论】:
标签: c# windows-services