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