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. Starting services programatically

Starting services programatically

Scheduled Pinned Locked Moved C#
question
5 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.
  • E Offline
    E Offline
    Esmo2000
    wrote on last edited by
    #1

    How do I start a service programatically? Is there a way to do it from the command prompt or in the service installer? Thanks a lot, Jim Did I post well? Rate it! Did I post badly? Rate that too!

    L 1 Reply Last reply
    0
    • E Esmo2000

      How do I start a service programatically? Is there a way to do it from the command prompt or in the service installer? Thanks a lot, Jim Did I post well? Rate it! Did I post badly? Rate that too!

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Add the System.ServiceProcess.dll as a reference and use System.ServiceProcess.ServiceController xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      E 1 Reply Last reply
      0
      • L leppie

        Add the System.ServiceProcess.dll as a reference and use System.ServiceProcess.ServiceController xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        E Offline
        E Offline
        Esmo2000
        wrote on last edited by
        #3

        Thanks, but how do I use that? I don't see a start command. Thanks, Jim Did I post well? Rate it! Did I post badly? Rate that too!

        H D 2 Replies Last reply
        0
        • E Esmo2000

          Thanks, but how do I use that? I don't see a start command. Thanks, Jim Did I post well? Rate it! Did I post badly? Rate that too!

          H Offline
          H Offline
          hooray
          wrote on last edited by
          #4

          try this: this.serviceController1 = new System.ServiceProcess.ServiceController("place here the name of the service"); serviceController1.Start();

          1 Reply Last reply
          0
          • E Esmo2000

            Thanks, but how do I use that? I don't see a start command. Thanks, Jim Did I post well? Rate it! Did I post badly? Rate that too!

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You didn't look very hard. ServiceController.Start Method[^] docs on MSDN.

            ServiceController myService = new ServiceController(@"MyServiceName");
            if ( (myService.Status.Equals(ServiceControllerStatus.Stopped) ) ||
            ( myService.Status.Equals(ServiceControllerStatus.StopPending) ) )
            {
            myService.Start();
            }
            else
            {
            Console.WriteLine("Service is already running...");
            }

            RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            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