title: Determining whether a service is already installed
body: <p>As part of installing my windows service I have coded an alternative to installutil and the command line:</p>
  
  <pre><code>IDictionary state = new Hashtable();
  using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MyServiceClass).Assembly, args))
  {
      IDictionary state = new Hashtable();
      inst.UseNewContext = true;
      //# Service Account Information
      inst.Install(state);
      inst.Commit(state);
  }
  </code></pre>
  
  <p>to intall it. I determing whether this needs doing by detecting whether it starts successfully. I anticipate delay between requesting it start and it actually setting it's RunningOk flag and would rather a generic, programmatic solution. The ( <a href="https://stackoverflow.com/questions/358700/how-to-install-a-windows-service-programmatically-in-c/637728#637728">How to install a windows service programmatically in C#?</a> ) <a href="http://dl.dropbox.com/u/152585/ServiceInstaller.cs" rel="nofollow noreferrer">http://dl.dropbox.com/u/152585/ServiceInstaller.cs</a> solution is nearly 3 years old, long, and imports DLL's which from the little I know about .NET seems to defeat its security intentions.</p>
  
  <p>Hence I would like to know of a more concise way to do this with .NET, if one exists?</p>