My Name is
I'm also known as @writeline
I'm a Technical Evangelist @ Microsoft Germany and you can follow me on Twitter or visit my private blog stream.
A customer asked me how to register his Enterprise Service App programmatically as NT-Service. There is no Attribute in the System.EnterpriseServices namespace do accomplish that. But you can do it yourself in an easy way. You have just to implement an own Installer derived class which is doing the registration stuff with help of a little component called RegistrationHelper. RegistrationHelper configures your Enterprise Service App the same way regsvcs.exe does. Additionally we need to use the COM Admin catalog components with its interface ICOMAdminCatalog2 which has the functionality we would like to use: CreateServiceForApplication. To use it in our installation class we have to create a primary interop assembly to keep our signed entity. To create a PIA just use tlbimp /keyfile:xyz.xyz /primary /out:COMAdmin.dll COMAdmin.dll. Following these simple guidelines we have just the following code:
public class InstallMyComponent : Installer
public override void Install(System.Collections.IDictionary stateSaver)
string applicationName = "Enterprise Services App as NT Service";
string tlbName = "ESAppAsService.tlb";
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
stateSaver.Add( "ApplicationName", applicationName );
stateSaver.Add( "TlbName", tlbName );
stateSaver.Add( "AssemblyName", assemblyName );
RegistrationHelper helper = new RegistrationHelper();
helper.InstallAssembly( assemblyName, ref applicationName, ref tlbName, InstallationFlags.FindOrCreateTargetApplication );
COMAdmin.ICOMAdminCatalog2 catalog = new COMAdmin.COMAdminCatalogClass();
catalog.CreateServiceForApplication( applicationName, "ESAppASNTService", "SERVICE_DEMAND_START",
"SERVICE_ERROR_NORMAL", "", null, null, false );
public override void Rollback(System.Collections.IDictionary savedState)
helper.UninstallAssembly( ( string ) savedState[ "AssemblyName" ],
( string ) savedState[ "applicationName" ] );
public override void Commit(System.Collections.IDictionary savedState)
This is how our installer class looks like. I know, there is no error handling, no uninstall routine and so forth. To register our app in COM+ use installutil.exe instead of regsvcs.exe. Viola!
I will update this post as the CodeClip will be available to demonstrate this.