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. Service will not start

Service will not start

Scheduled Pinned Locked Moved C#
questioncsharpcomworkspace
4 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.
  • S Offline
    S Offline
    spif2001
    wrote on last edited by
    #1

    Why can't I install and start a service using the following code? private void Test() { try { Process p = Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regsvcs", @"/fc C:\My.dll"); p.WaitForExit(); if(p.ExitCode != 0) { Console.WriteLine("My service install(RegSvcs) failed!!!"); Console.WriteLine("ExitCode was: "+p.ExitCode); return; } ServiceController sc = new ServiceController("My",Environment.MachineName); sc.Start(); Console.WriteLine("My service started!"); } catch(Exception ex) { Console.WriteLine("Install failed - Exception!!!"); Console.WriteLine(ex.ToString()); } } RegSvcs works fine and the service places itself in the COM+ services (I can see it via the ServiceComponents app), but when the code reaches sc.Start(), it throws an Exception with the following information: System.InvalidOperationException. Service My was not found on computer 'MBU'. InnerException = System.ComponentModel.Win32Exception (Danish)Den angivne tjeneste findes ikke som en installeret tjeneste (Translated)The service does not exists as an installed service Has it something to do with the service being a DLL and not an EXE and therefore you can't start it with a ServiceController? I can start it manually, by using the Componentservices app and right click on the "My" service. That means the service works, but just can't be started by the above shown code. What is going on?

    K 1 Reply Last reply
    0
    • S spif2001

      Why can't I install and start a service using the following code? private void Test() { try { Process p = Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regsvcs", @"/fc C:\My.dll"); p.WaitForExit(); if(p.ExitCode != 0) { Console.WriteLine("My service install(RegSvcs) failed!!!"); Console.WriteLine("ExitCode was: "+p.ExitCode); return; } ServiceController sc = new ServiceController("My",Environment.MachineName); sc.Start(); Console.WriteLine("My service started!"); } catch(Exception ex) { Console.WriteLine("Install failed - Exception!!!"); Console.WriteLine(ex.ToString()); } } RegSvcs works fine and the service places itself in the COM+ services (I can see it via the ServiceComponents app), but when the code reaches sc.Start(), it throws an Exception with the following information: System.InvalidOperationException. Service My was not found on computer 'MBU'. InnerException = System.ComponentModel.Win32Exception (Danish)Den angivne tjeneste findes ikke som en installeret tjeneste (Translated)The service does not exists as an installed service Has it something to do with the service being a DLL and not an EXE and therefore you can't start it with a ServiceController? I can start it manually, by using the Componentservices app and right click on the "My" service. That means the service works, but just can't be started by the above shown code. What is going on?

      K Offline
      K Offline
      krieg38
      wrote on last edited by
      #2

      As for as I know Services must be installed with a Setup Project to work corectly. I never used services, and I am not sure about this, just try it anyway.

      S 2 Replies Last reply
      0
      • K krieg38

        As for as I know Services must be installed with a Setup Project to work corectly. I never used services, and I am not sure about this, just try it anyway.

        S Offline
        S Offline
        spif2001
        wrote on last edited by
        #3

        That is actually what I am trying :), but I need a CustomInstall event to fire AfterInstall in order to start the service - but it doesn't. I'm in the high-fidelity first class traveling set. And I think I need a Lear jet.

        1 Reply Last reply
        0
        • K krieg38

          As for as I know Services must be installed with a Setup Project to work corectly. I never used services, and I am not sure about this, just try it anyway.

          S Offline
          S Offline
          spif2001
          wrote on last edited by
          #4

          Bad english - it does fire the afterinstall event. It is the sc.start() call that doesn't work.

          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