How to pass parameters to the executable when creating a service through sc.exe from command line in windows

Viewed 639

I am trying to create a service in windows using sc.exe to connect jenkins slave to master using swarm jar file.

I use the below command to create the service.

sc create jenkins-slave binPath= "java -jar C:\swarm-client-3.3.jar -master jenkins_master_url -username myuser -password mypass" start= auto

But when I start the service, it is giving me an error the system can not find the file specified.

I tried to put whole command in a batch file and tried to create the service but no luck. My doubt is whether we can pass arguments to the executable at all. If not is there any other better way ?

Any help on this will be appreciated.

1 Answers

I suggest to you, first, to convert the .jar and the commands related, to an .exe file.

You can do this using the Launch4j (http://launch4j.sourceforge.net/) utility directly on windows (Shall it work also on Linux, but it's harder to reach a compatible executable file for wWindows). Is a graphic tool that, passing the .jar archive with all the dependecies (builded before) it let you to have the .exe file ready to use.

Then, you could test the generated file, launching it and see it in the list of the services running.

Related