如何将我的应用程序作为Windows服务启动?

时间:2022-06-19 23:46:38

I have a windows application that I want to run as a windows service - how can I do this ?

我有一个Windows应用程序,我想作为Windows服务运行 - 我该怎么做?

5 个解决方案

#1


3  

You can use a tool to do this: XYNTService.

您可以使用工具执行此操作:XYNTService。

It is a service that can start regular applications, we use it at work and it also works with GUI apps. Since the service is running under the local SERVICE account, you can not see the GUI or access it in any way, because it is running in another winlogon session.

它是一种可以启动常规应用程序的服务,我们在工作中使用它,它也可以与GUI应用程序一起使用。由于服务在本地SERVICE帐户下运行,因此您无法以任何方式查看GUI或访问它,因为它在另一个winlogon会话中运行。

#2


2  

Quick-n-dirty way, use the INSTSRV and SRVANY tools in the Windows Resource Kit: How To Create a User-Defined Service

快速弄脏,使用Windows资源工具包中的INSTSRV和SRVANY工具:如何创建用户定义的服务

#3


1  

Solution for a .Net application that you have the source code:

If you project have a Controller and Business Logic well seperated (MVC) this will be very easy and fast.

如果你的项目有一个控制器和业务逻辑完全分离(MVC),这将非常容易和快速。

First, create a new project in your solution and select "Windows Service". This will create you a new project with a Program class that will contain a Main.

首先,在解决方案中创建一个新项目,然后选择“Windows服务”。这将创建一个包含Main的Program类的新项目。

Inside the Main you need to attach the Service Base class.

在Main内部,您需要附加Service Base类。

static class Program
{
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
        ServiceBase.Run(ServicesToRun);       
    }
}

Inside your service (the one who extend ServiceBase you need to override:

在您的服务中(扩展ServiceBase的人需要覆盖:

protected override void OnStart(string[] args)

To call your controller to start the job or you can simply start at while(...) with a thread.

要调用控制器来启动作业,或者只需使用线程从while(...)开始。

Otherwise, the link from Patrick Cuff is the good one.

否则,Patrick Cuff的链接就是好的。

#4


1  

Try this:

http://support.microsoft.com/kb/137890

It would work for any version of Windows. I've recently tested it with Server 2008.

它适用于任何版本的Windows。我最近使用Server 2008进行了测试。

#5


0  

In addition to XYNTService and SRVANY already recommended, you should consider AlwaysUp, a commercial product designed to run any application as a Windows Service. You can try it free for 30 days to ensure that it will do the job for you.

除了已推荐的XYNTService和SRVANY之外,您还应该考虑AlwaysUp,这是一种商业产品,旨在将任何应用程序作为Windows服务运行。您可以免费试用30天,以确保它能为您完成工作。

Good luck!

#1


3  

You can use a tool to do this: XYNTService.

您可以使用工具执行此操作:XYNTService。

It is a service that can start regular applications, we use it at work and it also works with GUI apps. Since the service is running under the local SERVICE account, you can not see the GUI or access it in any way, because it is running in another winlogon session.

它是一种可以启动常规应用程序的服务,我们在工作中使用它,它也可以与GUI应用程序一起使用。由于服务在本地SERVICE帐户下运行,因此您无法以任何方式查看GUI或访问它,因为它在另一个winlogon会话中运行。

#2


2  

Quick-n-dirty way, use the INSTSRV and SRVANY tools in the Windows Resource Kit: How To Create a User-Defined Service

快速弄脏,使用Windows资源工具包中的INSTSRV和SRVANY工具:如何创建用户定义的服务

#3


1  

Solution for a .Net application that you have the source code:

If you project have a Controller and Business Logic well seperated (MVC) this will be very easy and fast.

如果你的项目有一个控制器和业务逻辑完全分离(MVC),这将非常容易和快速。

First, create a new project in your solution and select "Windows Service". This will create you a new project with a Program class that will contain a Main.

首先,在解决方案中创建一个新项目,然后选择“Windows服务”。这将创建一个包含Main的Program类的新项目。

Inside the Main you need to attach the Service Base class.

在Main内部,您需要附加Service Base类。

static class Program
{
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
        ServiceBase.Run(ServicesToRun);       
    }
}

Inside your service (the one who extend ServiceBase you need to override:

在您的服务中(扩展ServiceBase的人需要覆盖:

protected override void OnStart(string[] args)

To call your controller to start the job or you can simply start at while(...) with a thread.

要调用控制器来启动作业,或者只需使用线程从while(...)开始。

Otherwise, the link from Patrick Cuff is the good one.

否则,Patrick Cuff的链接就是好的。

#4


1  

Try this:

http://support.microsoft.com/kb/137890

It would work for any version of Windows. I've recently tested it with Server 2008.

它适用于任何版本的Windows。我最近使用Server 2008进行了测试。

#5


0  

In addition to XYNTService and SRVANY already recommended, you should consider AlwaysUp, a commercial product designed to run any application as a Windows Service. You can try it free for 30 days to ensure that it will do the job for you.

除了已推荐的XYNTService和SRVANY之外,您还应该考虑AlwaysUp,这是一种商业产品,旨在将任何应用程序作为Windows服务运行。您可以免费试用30天,以确保它能为您完成工作。

Good luck!