gpt4 book ai didi

windows-services - 从可执行文件(INSTSRV.EXE 和 SRVANY.EXE)创建服务错误 - "Service started and then stopped"

转载 作者:行者123 更新时间:2023-12-01 16:43:02 26 4
gpt4 key购买 nike

我正在尝试使用我自己的可执行文件在 Windows 上创建服务。当我尝试启动该服务时,收到错误消息:

"The service on Local Computer started and thenstopped. Some services stop automatically if they have no work todo..."

该exe应该始终在工作,因为它不断运行一个计时器来检查时间并在一天中的某些时间点进行数据库备份。我已经单独测试了可执行文件(不是作为服务)并且它工作正常。

我使用批处理文件以及 INSTSRV.EXE 和 SRVANY.EXE 创建了该服务。批处理文件如下所示:

start /d "C:\<exe directory>" INSTSRV.EXE <service name> "C:\<exe
directory>\SRVANY.EXE"

服务器名称现在显示在我计算机上的服务列表中。我还编辑了注册表以确保一切正常。这是我的注册表条目的样子:

    Service key

DisplayName REG_SZ <service name>
ErrorControl REG_DWORD 0
ImagePath REG_EXPAND_SZ "C:\<exe directory>\SRVANY.EXE" <service name> C:\<exe directory>\SRVANY.EXE
ObjectName REG_SZ LocalSystem
Start REG_DWORD 2
Type REG_DWORD 16

Parameters key

AppDirectory REG_SZ E:\<exe directory>\
Application REG_SZ E:\<exe directory>\<exe file name>

我之前使用过类似的批处理文件来从可执行文件创建服务,并且我将该服务的注册表项与我自己的服务的注册表项进行了比较。它们非常相似。我不知道为什么我的服务不想启动。

最佳答案

您的 ImagePath 值似乎不正确。它应该只包含 Srvany 可执行文件的完整路径,仅此而已。

确实,当我将 Srvany 和 Instsrv 放在“C:\Apps\Win2K3RK”中并运行时:

C:\Apps\Win2K3RK\Instsrv.exe MyService C:\Apps\Win2K3RK\srvany.exe

创建的注册表项如下所示:

enter image description here

关于windows-services - 从可执行文件(INSTSRV.EXE 和 SRVANY.EXE)创建服务错误 - "Service started and then stopped",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23398520/

26 4 0
文章推荐: iOS 在 iPad 详细 Split View中更改 iAD 横幅大小
文章推荐: java - 将嵌套列表 List> 转换为 Set