简体   繁体   English

如何从Windows服务文件生成exe

[英]how can i generate exe from windows service file

I had created a Lib Project with a class inherits ServiceBase but when I run the solution i'm not getting the EXE file? 我创建了一个带有类继承ServiceBase的Lib项目,但是当我运行解决方案时,我没有得到EXE文件?

public class Scheduler : ServiceBase
{    
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] {new Scheduler()};
        Run(ServicesToRun);
    }
}

First, make sure that your project type is Windows Application , which is recommended for windows services. 首先,确保您的项目类型是Windows Application ,建议用于Windows服务。

What you did is not enough in order to install and start your service. 您所做的并不足以安装和启动您的服务。 You cannot yet install your service. 您还无法安装您的服务。 You have to provide an installer class which can then be used by InstallUtil to register your service. 您必须提供一个安装程序类,然后InstallUtil可以使用该类来注册您的服务。

You can see an example of this in the ServiceProcessInstaller class documentation. 您可以在ServiceProcessInstaller类文档中看到此示例。

After that, build your service again and install it by running in a command window the following: 之后,再次构建服务并通过在命令窗口中运行以下命令来安装它:

"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "YourServiceExeName.exe"

You will then be able to see your service in the services snap-in. 然后,您将可以在服务管理单元中查看您的服务。

Why not creating a project of type Windows Service ? 为什么不创建Windows服务类型的项目? and the installation part is already mentioned by the coon, but you need all the service exe path, not juste the service name. 并且安装部分已经由coon提及,但是您需要所有服务exe路径,而不是juste服务名称。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows服务:如何将多个Windows服务创建为多个exe文件 - Windows Service: How can i create multiple windows service as a multiple exe file 我如何使用 heat.exe(或类似的)从 Windows 服务中获取 COM 注册? - How can I use heat.exe (or similar) to harvest COM registration from a Windows Service? 如何使用 C# 从 Windows 服务运行 EXE 程序? - How can I run an EXE program from a Windows Service using C#? 如何创建一个独立的exe应用程序的Windows服务? - How can I create a windows service that is a standalone exe application? 从 Windows 服务卸载软件 - 为什么我不能从 Windows 服务调用 MSIEXE.EXE - Uninstall Software from Windows Service - Why can I not call MSIEXE.EXE from A Windows Service 如何从.NET Windows服务启动exe以更新服务 - How to start an exe from a .NET Windows Service for updating the service 我的Windows服务没有运行数据库连接的exe文件? - Exe file is not running from my Windows service with database connectivity? 如何启动从Windows服务运行bat文件的过程 - How can I start a process to run a bat file from a windows service 停止后如何修改Windows Service exe? - How can modify the windows service exe after its get stopped? 如何从exe服务运行exe并在exe进程退出时停止服务? - How to Run an exe from windows service and stop service when the exe process quits?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM