简体   繁体   English

如何从NSIS脚本使prunsvr工作

[英]how to make prunsvr work from NSIS script

I have an NSIS Script responsible for creating out installer. 我有一个NSIS脚本负责创建安装程序。 This installer copies files for our java application then uses prunsvr to install the windows service. 该安装程序将为我们的Java应用程序复制文件,然后使用prunsvr安装Windows服务。 When I run this targeting an EXE file built using launch for J, everything works. 当我运行此目标文件时,它使用J的启动文件生成了EXE文件,一切正常。 I want to be able to respond to WSM messages in my application to perform some cleanup / logging. 我希望能够在应用程序中响应WSM消息以执行一些清理/日志记录。 My NSIS script creates the service like so: 我的NSIS脚本如下创建服务:

ExecWait '"$INSTDIR\prunsrv.exe" "//IS//${Project}" --DisplayName="IPTI ${Project}" --Install="$INSTDIR\prunsrv.exe" --Classpath="$INSTDIR\Host Interface.jar" --StartMode="java" --StartClass="com.ipti.ptl.hostinterfaceservice.HostInterfaceService" --StopMode="java" --StopClass="com.ipti.ptl.hostinterfaceservice.HostInterfaceservice" --Startup="auto" --StartPath="$INSTDIR"'
ExecWait 'net start "IPTI ${Project}"'

The method above fails to create a service that will actually run but this method works fine (targeting an EXE) 上面的方法无法创建将实际运行的服务,但是此方法可以正常工作(针对EXE)

ExecWait '"$INSTDIR\prunsrv.exe" "//IS//${Project}" --DisplayName="IPTI ${Project}" --Install="$INSTDIR\prunsrv.exe" --StartMode=exe --StartImage="$INSTDIR\${Project}.exe" --Startup=auto --StartPath="$INSTDIR"'
ExecWait 'net start "IPTI ${Project}"'

I added the following to my main method to work with the prunsvr when not targeting an EXE: 我在不以EXE为目标的情况下,将以下内容添加到主要方法中以使用prunsvr:

public static void main(String[] args) throws Exception {
    Common.deployResources();
    if (args.length > 0 && args[0].equals("start")) {
        HostInterfaceService hi = new HostInterfaceService();
        hi.launch();
    }
    else {
        System.exit(0);
    }
}

I have also tried using start and stop methods specified with --StartClass --StartMethod --StopClass and --StopMethod. 我还尝试使用通过--StartClass --StartMethod --StopClass和--StopMethod指定的开始和停止方法。

No matter what I try, I invariably get an error. 无论我尝试什么,我总是会出错。 When I try to start from the service manager I get error code 1 or 4. No other information at all. 当我尝试从服务管理器启动时,出现错误代码1或4。根本没有其他信息。 What am I doing wrong? 我究竟做错了什么?

My event viewer shows only: 我的事件查看器仅显示:

The IPTI Host Interface service terminated with service-specific error Incorrect Function.

According to this Blog-Entry you have to rename prunsrv.exe to your Service Name. 根据此Blog-Entry,您必须将prunsrv.exe重命名为您的服务名称。

Maybe you can try it first with the Sample Service given there. 也许您可以首先使用此处提供的Sample Service尝试一下。

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

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