安装Windows编程服务 [英] Installing Windows Service programmatically
本文介绍了安装Windows编程服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何安装Windows服务编程,而无需使用installutil.exe?
How do I install a Windows Service programmatically without using installutil.exe?
感谢
推荐答案
您可以通过添加此code(在程序文件中,Program.cs中)自行安装使用指定的参数从命令行运行时,需要安装服务
You can install the service by adding this code (in the program file, Program.cs) to install itself when run from the commandline using specified parameters:
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (System.Environment.UserInteractive)
{
if (args.Length > 0)
{
switch (args[0])
{
case "-install":
{
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
break;
}
case "-uninstall":
{
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
}
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new MyService() };
ServiceBase.Run(ServicesToRun);
}
}
这篇关于安装Windows编程服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文