4

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

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Noah
  • 1,966
  • 1
  • 14
  • 29

2 Answers2

3

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% …
Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • Wow, that converts the spaces to FODLERNAME~1/2/etc.., and more importantly it works. Thank you very much. That's called a short name? – Noah Aug 08 '11 at 14:29
  • A short name, yes. Every particular name in the converted path is no longer than 8 characters, and may have an extension of up to 3 characters. – Andriy M Aug 08 '11 at 17:40
  • Looked it up, thanks again. Something I never knew widows could do. – Noah Aug 08 '11 at 20:00
  • It would be good to know what the magic `prunsrv=%%~sF` does. And if there are any risks or cases where `%%~sF` fails – user1338413 Mar 16 '15 at 10:50
1

I know this is old but a bit less clever solution is:

set JVM_DLL="c:\Program Files\Java\jre6\bin\server\jvm.dll"

prunsrv //IS//%SERVICE_NAME% --Jvm=%JVM_DLL%

Greg L.
  • 286
  • 2
  • 4
  • 9