简体   繁体   中英

how to make prunsvr work from NSIS script

I have an NSIS Script responsible for creating out installer. This installer copies files for our java application then uses prunsvr to install the windows service. When I run this targeting an EXE file built using launch for J, everything works. I want to be able to respond to WSM messages in my application to perform some cleanup / logging. My NSIS script creates the service like so:

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)

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:

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.

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. 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.

Maybe you can try it first with the Sample Service given there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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