Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to specify a service name in the app.config file?

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.

like image 657
Blerta Avatar asked Jul 09 '09 10:07

Blerta


People also ask

What information is contained in the app config file?

App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.

What is difference between web config and app config?

config is parsed at runtime, so if you edit the web. config file, the web application will automatically load the changes in the config file. Â app. config is parsed at compile time, so if you edit the app.

What is the use of app config file in C#?

By adding an application configuration file (app. config file) to a C# project, you can customize how the common language runtime locates and loads assembly files. For more information about application configuration files, see How the runtime locates assemblies (. NET Framework).


2 Answers

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"

like image 158
Blerta Avatar answered Oct 05 '22 23:10

Blerta


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).

like image 28
Umar Farooq Khawaja Avatar answered Oct 05 '22 22:10

Umar Farooq Khawaja