Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. making windows services configurable

making windows services configurable

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasehelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asad Hussain
    wrote on last edited by
    #1

    I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??

    G P 2 Replies Last reply
    0
    • A Asad Hussain

      I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??

      G Offline
      G Offline
      Guillermo Rivero
      wrote on last edited by
      #2

      I've done this using a configuration file, and if you don't like it, you can use the registry. Free your mind...

      1 Reply Last reply
      0
      • A Asad Hussain

        I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??

        P Offline
        P Offline
        Pratik Desai
        wrote on last edited by
        #3

        You can add an entry in the web.config file in the tag. eg. You can than read this entry using ConfigurationSettings.AppSettings("keyname")

        C 1 Reply Last reply
        0
        • P Pratik Desai

          You can add an entry in the web.config file in the tag. eg. You can than read this entry using ConfigurationSettings.AppSettings("keyname")

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          I think you mean the app.config file. web.config is just for ASP.NET applications. Anyway, for the original poster... In visual studio make sure the project of your windows service has an app.config file, you use it just like the web.config file (see Pratik Desai's post above). When you deploy your application Visual Studio will change the name from app.config to myWindowsService.exe.config or whatever the exe file is called + .config. I have a feeling that the config file is only read once (I'm not sure if you can force it to re-read it to check for changes if it is only read once) in which case your service will have to be restarted. --Colin Mackay--

          "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

          A 1 Reply Last reply
          0
          • C Colin Angus Mackay

            I think you mean the app.config file. web.config is just for ASP.NET applications. Anyway, for the original poster... In visual studio make sure the project of your windows service has an app.config file, you use it just like the web.config file (see Pratik Desai's post above). When you deploy your application Visual Studio will change the name from app.config to myWindowsService.exe.config or whatever the exe file is called + .config. I have a feeling that the config file is only read once (I'm not sure if you can force it to re-read it to check for changes if it is only read once) in which case your service will have to be restarted. --Colin Mackay--

            "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

            A Offline
            A Offline
            Asad Hussain
            wrote on last edited by
            #5

            So whenever I want to deploy the windows service, I have to copy the app.config file with it? If the app.config file is all I have to modify, restarting the windows service isnt really a hassle. Thanx

            C 1 Reply Last reply
            0
            • A Asad Hussain

              So whenever I want to deploy the windows service, I have to copy the app.config file with it? If the app.config file is all I have to modify, restarting the windows service isnt really a hassle. Thanx

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Yes, but remember that when you build your application windows will copy the app.config into your Debug or Release folder and rename it with the name of the exe with the addition of the .config. Also - And it took me a while to figure out why it wasn't working the way I expected - The config file is not read while the windows service is installing. So your installer class can't access it without a lot of extra work. --Colin Mackay--

              "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups