apachebatch-filewindows-servicesprocrun

Creation of service with spaces in install path


I am creating a Windows service using Apache's procrun, and I'm having difficulty getting it set up properly. I'm using a batch file to execute the procrun install. My question is two fold.

  1. I'm unable to create a service with spaces in the name. This example was taken from Apache and is setting up a prunsrv service install:

    prunsrv //IS//TestService --DisplayName="Test Service" \
        --Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm \
        --StartClass=org.apache.SomeStartClass --StartParams=arg1;arg2;arg3 \
        --StopClass=org.apache.SomeStopClass --StopParams=arg1#arg2
    

    I have an installed service somewhere in C:\Program Files\, which has a space. I need the --Install path to be 'C:\Program Files\prunsrv.exe' to correctly point to the right path. If I don't inclose the path with quotes:

    --Install=C:\Program Files\prunsrv.exe
    

    Windows service thinks the install path is:

    C:\Program
    

    Which is an invalid location. When I use:

    --Install="C:\Program Files\prunsrv.exe"  (or) 
    "--Install=C:\Program Files\prunsrv.exe"
    

    Windows service thinks the install path is:

    "C:\Program Files\prunsrv.exe"
    

    ...which is also an invalid location (it literally tries to execute that path with the quotes.)

    Does anyone know how to correctly install a Windows service with spaces in the path?

  2. If further complications arise, it would be nice to have more detailed documentation. Does anyone have any additional documentation for procrun or examples of it being used? The list of resources I have found this far is:

    It looks like a good resource used in other questions is no longer available: http://blog.platinumsolutions.com/node/234


Solution

  • For the question #1, you could try using the equivalent path consisting only of short names. It is possible to convert a long-name path with the help of a FOR loop:

    FOR %%F IN ("C:\Program Files\prunsrv.exe") DO SET prunsrv=%%~sF
    prunsrv … --Install=%prunsrv% …