1

Anybody know of a way to pass the namespace parameter to the InstrumentedAttribute constructor in the ProjectInstaller or any installer?

It's a Windows Service. The ProjectInstaller is below, but pretty standard.

I want to set the InstrumentedAttribute NamespaceName in code after pulling it from say the config file, rather than setting it in the following attribute:

<Assembly: Instrumented("Root/EnRoute/Interfaces/Spill")>

I'm guessing I need a custom InstrumentedAttribute constructor, but can't figure out how to do it.

The ProjectInstaller:

Imports System.Management.Instrumentation

<Assembly: Instrumented("Root/EnRoute/Interfaces/Spill")>    ', "G:S-1-1-0"
Public Class ProjectInstaller

    Public Sub New()
        MyBase.New()

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

        'Add initialization code after the call to InitializeComponent
        Dim managementInst As New ManagementInstaller
        Installers.Add(managementInst)
    End Sub
    ''' <summary>
    ''' add config file name to the registry ImagePath for spill interface(s) 
    ''' that are not the default interface
    ''' </summary>
    ''' <param name="stateSaver"></param>
    Public Overrides Sub Install(stateSaver As IDictionary)
        MyBase.Install(stateSaver)
        If Context.Parameters.ContainsKey("configName") Then
            ' write the config name to include the group name (law, fire, a, b, 1, blah, whatever)
            ' example: EnRoute.Interface.Spill.<groupname>.Service.exe.config
            Dim system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System")
            Dim currentControlSet = system.OpenSubKey("CurrentControlSet")
            Dim services = currentControlSet.OpenSubKey("Services")
            Dim service = services.OpenSubKey(Me.ServiceInstaller1.ServiceName, True)
            service.SetValue("Description", Me.ServiceInstaller1.ServiceName + " Service")
            Dim config = service.CreateSubKey("Parameters")
            config.SetValue("Arguments", Command)
            Console.WriteLine(service.GetValue("ImagePath"))
            service.SetValue("ImagePath", service.GetValue("ImagePath") & " " & Context.Parameters.Item("configName"))
        End If

    End Sub
    Protected Overrides Sub OnBeforeInstall(savedState As IDictionary)
        MyBase.OnBeforeInstall(savedState)
        Me.ServiceInstaller1.DisplayName = "EnRoute Interface Spill"
        Me.ServiceInstaller1.ServiceName = "EnRoute Interface Spill"
    End Sub

    Protected Overrides Sub OnBeforeUninstall(savedState As IDictionary)
        MyBase.OnBeforeUninstall(savedState)
        Me.ServiceInstaller1.DisplayName = "EnRoute Interface Spill"
        Me.ServiceInstaller1.ServiceName = "EnRoute Interface Spill"
    End Sub
End Class
RBT
  • 24,161
  • 21
  • 159
  • 240

0 Answers0