简体   繁体   English

如何制作自定义Windows服务?

[英]How do I make a custom windows service?

Actually I am having one java program. 其实我有一个java程序。 That returns "Hello World". 返回“Hello World”。 I converted it to jar file. 我把它转换成了jar文件。 After that I changed the file type as .exe with the use of iexpress in my windows XP default sw. 之后,我在Windows XP默认sw中使用iexpress将文件类型更改为.exe。

I used the sc create command, for creating new service. 我使用sc create命令来创建新服务。 I created the windows service successfully. 我成功创建了Windows服务。 But the thing is I am not able to run this. 但问题是我无法运行它。 It is throwing the following error. 它抛出以下错误。

在此输入图像描述

This error is coming not only for this javaservice. 这个错误不仅会出现在这个javaservice中。

I tried to run the chrome.exe as windows service, That time also it is throwing the same error. 我试图将chrome.exe作为windows服务运行,那个时候它也抛出同样的错误。

Is it windows constraints? 是窗户约束吗? or Am I making mistake? 还是我弄错了? Expecting the solution., 期待解决方案。,

Thanks in Advance... 提前致谢...

You cannot just assign any arbitrary .exe file as-is to run as a service. 您不能只是按任意方式分配任何.exe文件作为服务运行。 There are specific API functions involved that services must use to interact with the Service Control Manager (SCM). 服务必须使用特定的API函数来与服务控制管理器(SCM)进行交互。 That is why you are getting the errors - those .exe files are not using those APIs to interact with the SCM. 这就是您收到错误的原因 - 那些.exe文件没有使用这些API与SCM交互。

If you are not writing code specifically for SCM interaction (Java does not support creating Windows services), then all is not lost. 如果您不是专门为SCM交互编写代码(Java不支持创建Windows服务),那么所有代码​​都不会丢失。 In some situations (Chrome NOT being one of them!), you can use a separate wrapper to host non-service apps and handle the SCM interactions on their behalf: 在某些情况下(Chrome 不是其中之一!),您可以使用单独的包装器来托管非服务应用并代表他们处理SCM交互:

Service wrapper 服务包装器

For Java apps, there are a few wrapper projects available: 对于Java应用程序,有一些可用的包装器项目:

Java Service Wrapper Java Service Wrapper

Yet Another Java Service Wrapper 又一个Java服务包装器

ow2 OW2

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM