Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I start a service with certain parameters? In another question I have found

net start servicename blah

but if I try this, net throws a syntax error at me.

What am I doing wrong?

Edit: To clarify net start servicename works just fine, but I need to pass parameters to the service. I can do this manually in services.msc by filling in a start parameter before starting the service. But how can I do this from a script?

Another edit: Sorry, but my question was misleading. In my tests, I had many more parameters and it's not the /blah net start complains about. In fact, anything starting with a slash is fine. So net start servicename /blah works, net start servicename blah doesn't work. Since I need net start servicename /foo bar, it's the bar that is the problem.

share|improve this question
add comment

5 Answers

up vote 7 down vote accepted
sc start fooservice arg1 arg2 ...
share|improve this answer
    
I have no idea how I managed to miss your answer back then, but I'm certainly very glad I found it now (by accident). This works like a charm - even with parameters that don't start with /. Thanks a lot! –  sbi Jun 2 '10 at 15:43
add comment

NET START won't allow you to pass arbitrary parameters as far as I know (it appears they have to be prefixed with a /), I believe the correct way is to modify the appropriate registry key and stop/start the service. Assuming your custom service is called MyService:

[HKLM\SYSTEM\CurrentControlSet\Services\MyService]
"ImagePath":C:\Projects\MyService\bin\MyService.exe Parameter1 Parameter2

Really though, a better way is to store your configuration somewhere the service knows about, like perhaps the registry or file system, and read whatever values you need. As you can see customizing the command line is a bit more painful than it should be.

If this is by chance a .NET developed service, you could create n copies of the executable on your file system, and have each automatically get the parameters from the appropriate app.config file.

It sounds like you may have stepped too far outside the Win32 box. Since this sounds like custom development any of the other offered solutions, while perhaps not your ideal, will work correctly and are a safer way to go.

share|improve this answer
    
Ugh. The service takes a configuration file. It either uses a default file name or one passed to it. Since I need two different instances of the service running, I need to point them at different configuration files. Having to fiddle with the registry seems a very ugly hack. Is there really no other way than that (and the GUI)? –  sbi May 19 '10 at 14:03
    
Goyuix, see my edited question. net start does accept parameters, but only those starting with a /. –  sbi May 19 '10 at 14:43
    
Goyuix, I now use sc.exe. See grawity's answer (which I somehow managed to miss back then). –  sbi Jun 2 '10 at 15:45
add comment

You need a slash before each parameter when using net start. Also make sure to quote parameters that have spaces.

net start servicename /param0 /"param1 with spaces" /"/param2_has_slash"
share|improve this answer
    
Look again at my problem. I do have parameters that (have to) start with a slash, too. How would I pass those then? –  sbi Mar 19 '12 at 11:13
    
Try this: net start servicename /"/foo" /bar –  Even Mien Mar 27 '12 at 19:51
add comment

You need to use the actual service name as it appears in control panel, services. If it contains spaces, you must put quotes around the service name.

To get the actual service name just type in net start without any parameters on the command prompt. It should give you a list of all the running services so you can get the actual service name. Then just use net start <servicename>

share|improve this answer
    
Robert, it's a service of mine which I install and then start in a script. I do net start "my-service-name" just fine. It's net start "my-service-name" /blah which gives me an error message. I've also tried net start "my-service-name" -blah and this, too, is a syntax error. –  sbi May 19 '10 at 13:35
add comment

Could InstSrv and SrvAny assist in this? Guide and Links

share|improve this answer
    
I have looked at it briefly and I don't think so. (Please correct me if I'm wrong.) I have a real service executable up and running just fine. It's just that (for tests) I need to install and start it from a script, and I need to pass parameters to the service. –  sbi May 19 '10 at 13:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.