Easier .NET Service installation 2

Also, removing a .NET Windows Service that is running under an account other than Local System/Local Service lingers in the list of services until a restart. Adding the snippet below in the project installer will reset the account to local system just before the actual uninstall. This neatly removes the service from the list.

/// <summary>
///
Overriden to set the user account to local service.
/// If set to custom user on uninstall the service entry lingers until a reboot,
/// when set to local service the entry is removed immediately.
/// </summary>
///
<param name="savedState">Only passed to base class.</param>
protected override void OnBeforeUninstall(IDictionary savedState)
{
      
this.serviceProcessInstaller.Account = ServiceAccount.LocalService;
      
base.OnBeforeUninstall(savedState);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s