[英]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.