windows - 将 GHC 创建的 Windows 可执行文件作为服务运行

标签 windows haskell windows-services ghc

我使用 GHC 7.6.3 32 位Windows Server 2008 上编译了一个程序。我试图在启动时通过 Windows 内的服务运行它(并且最好保持运行)。为此,我已使用以下命令成功创建了一个服务

sc create stworker binPath= "C:\Users\vagrant\Desktop\worker.exe"

我遇到的问题是,当我尝试启动服务时,我收到以下错误(见下图)。

当我双击可执行文件时,它运行良好。所以不确定为什么 Windows 不允许运行该服务。

我认为这不是 GHC 的问题。我假设 GHC 编译为 native 代码而不是 MSIL。

那么有什么想法为什么我无法将可执行文件作为服务运行吗?

enter image description here

最佳答案

正如评论中提到的,您需要实际实现 Win32 服务 API,以使您的程序充当 Windows 服务,您可以使用 Win32-services 来完成此操作。包。

还有一个包装包Win32-services-wrapper我写的旨在提供一些样板文件并处理日志记录,以便定义服务如下所示:

main =
    defineService $
        Service {
            serviceName = "Service",
            -- Start the service given a debug handle to write to.
            -- Make sure not to use stdout or stderr as they don't exist.
            -- Any state needed by serviceStop can be returned here -
            -- the Service type takes the type of the state as a type parameter
            serviceStart = \debugHandle -> ...,
            -- Stop the service given the service state returned by serviceStart
            serviceStop = \serviceState -> ...
        }

darcsden中有一个使用它的真实例子.

关于windows - 将 GHC 创建的 Windows 可执行文件作为服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748419/

相关文章:

c++ - Visual Studio C++ 添加可部署内容(整个文件夹)

c++ - 关于我的教科书示例中的 GDI 映射

haskell - 为什么 Haskell 标准库中没有 <<?

haskell - 定义一个函数,将给定列表的所有可能排列返回为对列表

haskell - 余积与求和类型相同吗?

windows - 突然之间,perl 脚本不起作用,除非我在它们前面加上 "perl"并提供脚本的完整路径

windows - 如何使用PowerShell将作者添加到Windows任务

c# - Topshelf vs sc.exe vs Windows 服务项目类型

.net - Windows 安装程序 : Error 1001, CustomAction _xxxxx.install 返回实际错误代码 1603

c# - 64 位 Windows 服务但需要 32 位 dll