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. C#
  4. Windows Service name/description

Windows Service name/description

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 2 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.
  • P Offline
    P Offline
    petst
    wrote on last edited by
    #1

    Hi all, Does anybody know how to set a windows service description? The serverinstaller component's Displayname property maps to the Service Name in the Services MMC snap-in. The Description in the MMC is empty. I can't find any property that maps to this description. Thanks, Peter

    H 1 Reply Last reply
    0
    • P petst

      Hi all, Does anybody know how to set a windows service description? The serverinstaller component's Displayname property maps to the Service Name in the Services MMC snap-in. The Description in the MMC is empty. I can't find any property that maps to this description. Thanks, Peter

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Since the ServiceInstaller doesn't define such a property, you have to write it to the registry yourself. The easiest way is, in your Installer derivative (the class that references the ServiceInstaller and ServiceProcessInstaller), override Install (and Uninstall with code to remove the key) like so:

      public override void Install(IDictionary stateSaver)
      {
      base.Install(stateSaver);
      using (RegistryKey key = Registry.LocalMachine.OpenSubkey(
      @"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName))
      {
      if (key != null)
      key.SetValue("Description", description);
      }
      }
      string description;
      public string Description
      {
      get { return description; }
      set { description = value; }
      }

      You wouldn't have to define it as a property, but it makes for a good design. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      P 1 Reply Last reply
      0
      • H Heath Stewart

        Since the ServiceInstaller doesn't define such a property, you have to write it to the registry yourself. The easiest way is, in your Installer derivative (the class that references the ServiceInstaller and ServiceProcessInstaller), override Install (and Uninstall with code to remove the key) like so:

        public override void Install(IDictionary stateSaver)
        {
        base.Install(stateSaver);
        using (RegistryKey key = Registry.LocalMachine.OpenSubkey(
        @"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName))
        {
        if (key != null)
        key.SetValue("Description", description);
        }
        }
        string description;
        public string Description
        {
        get { return description; }
        set { description = value; }
        }

        You wouldn't have to define it as a property, but it makes for a good design. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        P Offline
        P Offline
        petst
        wrote on last edited by
        #3

        Fot those interrested, Heath's hint returns a read-only reference to the registry key. Few bytes changed and it works: public override void Install(IDictionary stateSaver) { this.Description = "Blah blah."; base.Install(stateSaver); string p = @"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName; RegistryKey key = Registry.LocalMachine.OpenSubKey(p,true); { if (key != null) key.SetValue("Description", description); } } Ciao and thanks for your help Heath! Peter

        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