Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can write a self-installing service and have it set a list of services your service depends on when the installer is executed.</p> <p>Basic steps:</p> <ul> <li>Add a reference to System.Configuration.Install to your project.</li> <li>Add a class that derives from <a href="http://msdn.microsoft.com/en-us/library/system.configuration.install.installer.aspx" rel="noreferrer">System.Configuration.Install.Installer</a> and has the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.runinstallerattribute.aspx" rel="noreferrer">RunInstaller attribute</a> applied.</li> <li>In its constructor create both a <a href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceprocessinstaller(VS.80).aspx" rel="noreferrer">ServiceProcessInstaller</a> and a <a href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller(VS.80).aspx" rel="noreferrer">ServiceInstaller</a> object.</li> <li>On the ServiceInstaller object you mark all the dependencies you want/need with the <a href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.servicesdependedon(VS.80).aspx" rel="noreferrer">ServicesDependedOn</a> property.</li> <li>Add these two installers to the <a href="http://msdn.microsoft.com/en-us/library/system.configuration.install.installercollection(VS.80).aspx" rel="noreferrer">InstallersCollection</a> your installer inherited from System.Configuration.Install.Installer</li> <li>done.</li> </ul> <p>edit: forgot to mention that you can use e.g. <a href="http://msdn.microsoft.com/en-us/library/50614e95.aspx" rel="noreferrer">Installutil.exe</a> to invoke the installer.</p> <pre><code>[RunInstaller(true)] public class MyServiceInstaller : Installer { public MyServiceInstaller() { using ( ServiceProcessInstaller procInstaller=new ServiceProcessInstaller() ) { procInstaller.Account = ServiceAccount.LocalSystem; using ( ServiceInstaller installer=new ServiceInstaller() ) { installer.StartType = ServiceStartMode.Automatic; installer.ServiceName = "FooService"; installer.DisplayName = "serves a lot of foo."; installer.ServicesDependedOn = new string [] { "CLIPBOOK" }; this.Installers.Add(procInstaller); this.Installers.Add(installer); } } } }</code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload