简体   繁体   English

从 .NET 安装服务应用程序不会安装它

[英]installing a service app from .NET does not install it

I have read the other similar posts on this forum, However they haven't helped me I'm using Visual Studio 2019 Team System.我已阅读此论坛上的其他类似帖子,但它们对我没有帮助我正在使用 Visual Studio 2019 Team System。 on Windows 10, My Windows account has admin privileges: Here is what I have done to achieve this.关于 Windows 10、我的 Windows 帐户具有管理员权限: 以下是我为实现此目的所做的工作。 Service app created and worker code independantly tested also the class on business.. i'm installing the service from cmd whit InstallUtil.exe: this is the code of the service:创建了服务应用程序并独立测试了 class 的工作人员代码。我正在从 cmd 安装服务和 InstallUtil.exe:这是服务的代码:

public partial class Service : ServiceBase
{
    #region Abstracción clases 
    BLTerminal terminalService = new BLTerminal();
    Timer timer;
    protected FileSystemWatcher watcher;
    DAGeneral dAGeneral = new DAGeneral();
    #endregion
    #region Declaración de Variables
    string pathToFolder = ConfigurationManager.AppSettings["pathToFolder"];
    string targetPath = ConfigurationManager.AppSettings["targetPath"];
    string extension = ConfigurationManager.AppSettings["extensionFile"];
    string logPath = ConfigurationManager.AppSettings["logPath"];
    string TimeInterval = ConfigurationManager.AppSettings["TimeInterval"];
    string TimeEnabled = ConfigurationManager.AppSettings["TimeEnabled"];
    #endregion

    public void OnDebug()
    {
        OnStart(null);
    }

    #region Método del Servicio
    public Service()
    {
        InitializeComponent();
    }
    #endregion
    #region Metódo OnStart del servicio
    protected override void OnStart(string[] args)

    {
        try
        {
            timer = new Timer();
            terminalService.LogService("Service is started at " + DateTime.Now.ToString("dd/MM/yyyy_HH:mm:ss"), logPath);
            timer.Interval = Convert.ToDouble(TimeInterval);
            timer.Enabled = Convert.ToBoolean(TimeEnabled);
            terminalService.CreateBackup(pathToFolder, targetPath, extension, logPath);
        }
        catch (Exception ex)
        {
            dAGeneral.GuardarLogTerminalService(36, 1, $"error: ", ex.Message);
        }
    }
    #endregion

    #region Metódo OnStop del servicio
    protected override void OnStop()
    {
        terminalService.LogService("Service is stopped at " + DateTime.Now.ToString("dd/MM/yyyy_HH:mm:ss"), logPath);
    }
    #endregion
    #region Método de OnelapsedTime del servicio
    private void OnElapsedTime(object source, ElapsedEventArgs e)
    {
        terminalService.LogService("Service is recall at " + DateTime.Now.ToString("dd/MM/yyyy_HH:mm:ss"), logPath);
    }
    #endregion
}

You have defined the service itself for .NET Framework 4, but you are missing the installer.您已经为 .NET Framework 4 定义了服务本身,但缺少安装程序。 The installer is a class that you can define manually or with the help of the designer that is invoked when your assembly is registered via InstallUtil.exe安装程序是一个 class,您可以手动定义或在通过 InstallUtil.exe 注册程序集时调用的设计器的帮助下定义

You can have a look at here .你可以在这里看看。 The link refers .NET 4.链接参考.NET 4.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM