views:

167

answers:

4

I want to specify my service name in the app.config without needing to recomple and install/uninstall my service repeatedly. But just retrieving service name from app.config, the service seems ignoring it. Are there any special tricks how to obtain this? Thanks in advance.

I mean classic windows service. I don't think any code is needed here. I just want to retrieve the service name from app.config dynamically.

+2  A: 

Assuming you mean Windows Service, the answer is no. The service has to be installed in the registry, and the name is one of the registry keys.

John Saunders
+4  A: 

After searching a while on the internet and reading articles, it became clearer to me that A service name can't be specified in the app.config in so dynamic way, instead sc command can be used to perform a similar solution. You can specify other configuration variables in the app.config and use sc to rename it

sc.exe create "servicename" binPath="myservicepath.exe"

Izabela
+2  A: 

I'm afraid that what you are trying to do its not possible. It actually seems to go against the nature of a Windows Service purpose and current behavior.

After a windows service is installed the name can't be changed without re-installing it again. What actually names the service is an element called service installer. Which by now, I assume you know what it is and where its located.

However there are ways of manipulating an installed service by using Windows Management Instrumentation (WMI). Maybe this combined with Izabela's recommendation become the right path to your solution.

I would recommend you to read the following tutorial, you might find an alternate way of achieving what you're trying to do.

http://www.serverwatch.com/tutorials/article.php/1576131/Windows-Services-Management-With-WMI-Part-1.htm

Raúl Roa
+3  A: 

I am not sure what scenario you have in mind. You would like the name of your Windows service to change. Fair enough. When would it change?

Imagine you have found the solution and created such a Windows service. I presume in your scenario you would install it at least the first time. Then you do not want to uninstall/install it. But presumably you would like to start/stop and do other things with it. Will one of those actions cause the name of the service to change?

If so, I imagine you could launch a process that uninstalls and installs it with a different name for you transparently, based on some kind of naming logic.

I don't see how else you could do it.

Or just come up with a really generic name to cover all possibilities (which might be incredibly simple or incredibly difficult).

Umar Farooq Khawaja
I totally agree with you
Raúl Roa