SoFunction
Updated on 2025-03-06

C# developed program dynamically specifies the Windows service name when installing the installation of the program


SettingHelper
#region File Description
//-------------------------------------------------------------------------------------------------
// Description: Service installation configuration help class
// Author: Bao Haosheng
// Time: 2012-05-10
//-------------------------------------------------------------------------------------------------
#endregion
using System;
using ;
using ;
/// <summary>
/// Service installation configuration help class
/// </summary>
internal class SettingHelper : IDisposable
{
#region Private Member
private string _ServiceName;
private string _DisplayName;
private string _Description;
#endregion
#region constructor
/// <summary>
/// Initialize the service configuration help class
/// </summary>
public SettingHelper()
{
InitSettings();
}
#endregion
#region properties
/// <summary>
/// The system is used to mark the name of this service
/// </summary>
public string ServiceName
{
get { return _ServiceName; }
}
/// <summary>
/// Log the friendly name of the service to the user
/// </summary>
public string DisplayName
{
get { return _DisplayName; }
}
/// <summary>
/// Service description
/// </summary>
public string Description
{
get { return _Description; }
}
#endregion
#region Private Method
#region Initialization Service Configuration Information
/// <summary>
/// Initialize service configuration information
/// </summary>
private void InitSettings()
{
string root = ().Location;
string xmlfile = (('\\') + 1) + "";
if ((xmlfile))
{
XmlDocument doc = new XmlDocument();
(xmlfile);
XmlNode xn = ("Settings/ServiceName");
_ServiceName = ;
xn = ("Settings/DisplayName");
_DisplayName = ;
xn = ("Settings/Description");
_Description = ;
doc = null;
}
else
{
throw new FileNotFoundException("Server name configuration file not found!");
}
}
#endregion
#endregion
#region IDisposable Member
private bool disposed = false;
public void Dispose()
{
Dispose(true);
(this);
}
protected virtual void Dispose(bool disposing)
{
if (!)
{
if (disposing)
{
//managed dispose
_ServiceName = null;
_DisplayName = null;
_Description = null;
}
//unmanaged dispose
}
disposed = true;
}
~SettingHelper()
{
Dispose(false);
}
#endregion
}