0

关于 Windows 服务的快速问题,我为我的 Windows 服务添加了一个设置项目,并添加了一个自定义对话框,带有 4 个文本字段,但我的问题是如何获取这些信息/变量?

我还为 Windows 服务添加了一个安装程序,然后是安装项目,带有自定义对话框。

信息类似于数据库连接字符串等 - 所以只是字符串值。

这是我的“项目安装程序”代码。如果您想查看我为 Windows 服务添加的安装程序项。

    Imports System
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.Runtime.InteropServices



Public Class ProjectInstaller

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        My.Settings.TestSetting = Context.Parameters.Item("PathValue")

#If DEBUG Then

        Dim ServicesToRun As ServiceBase()
        ServicesToRun = New ServiceBase() {New tdsCheckService()}
        ServiceBase.Run(ServicesToRun)

#Else

        Dim listener As New tdsCheckService()
        listener.Start()

#End If

    End Sub

    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        Dim regsrv As New RegistrationServices
        regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
    End Sub
    Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
        MyBase.Uninstall(savedState)
        Dim regsrv As New RegistrationServices
        regsrv.UnregisterAssembly(MyBase.GetType().Assembly)
    End Sub

    Private Sub ServiceProcessInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceProcessInstaller1.AfterInstall

    End Sub

    Private Sub ServiceInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceInstaller1.AfterInstall

    End Sub
End Class
4

1 回答 1

0

您应该能够使用 Context 对象访问它们。

 'Get Protected Configuration Provider name from custom action parameter
        Dim variableName As String = Context.Parameters.Item("dialogSettingName")


  Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
    MyBase.Install(stateSaver)
于 2012-09-27T14:02:46.937 回答