带有GUI前端的Windows Service应用程序

时间:2014-02-01 03:03:00

标签: .net vb.net c#-4.0

我正在尝试使用另外包含Windows窗体的VB.net 2010编写Windows服务,以便管理员可以在安装服务后加载Windows窗体GUI(以便他们可以更改存储的某些属性)来自核心项目的My.Settings。<config file>

我想在构建项目后有一个单独的.exe可执行文件(因此运行它的人可以使用installutil.exe安装服务或运行GUI应用程序) - 但是他们必须在同一个项目中,因为我需要GUI来从存储在应用程序 .exe.config

中的My.Settings.Properties访问存储的属性

我该如何做到这一点?

1 个答案:

答案 0 :(得分:2)

  1. 创建GUI应用程序。
  2. 然后将服务类添加到它。
  3. 现在您可以通过InstallUtil安装该服务。

    或者您可以直接从Explorer或Cmd.exe运行.exe,GUI将打开。

    服务和GUI都将从同一个配置文件中读取,因为它们是相同的程序集。

    当然,这只是一种方法。 @ T.S。提供了另一种方法,如果正确实施,它将同样有效。

    如何做到这一点的简要说明:
    1.创建WinForms应用程序
    2.为System.Configuration.Install和System.ServiceProcess添加引用 3.创建继承自System.ServiceProcess.ServiceBase的服务类,并覆盖相应的方法 4.创建继承自System.Configuration.Install.Installer的安装程序 5.使用RunInstaller(True)属性标记安装程序类 6.使安装程序.ctor看起来像这样:

        Public Sub New()
            Dim spi As ServiceProcessInstaller = New ServiceProcessInstaller
        Dim si As ServiceInstaller = new ServiceInstaller
    
        spi.Account = ServiceAccount.LocalSystem
    
            si.StartType = ServiceStartMode.Manual
            si.ServiceName = "Service1"
    
            Installers.Add(si)
            Installers.Add(spi)
    
        End Sub