Robert McLaws: FunWithCoding.NET

Public Shared Function BrainDump(ByVal dotNet As String) As [Value]

News

<script type="text/javascript"><!-- google_ad_client = "pub-4330602465258980"; google_hints = "ASP.NET, VB.NET, C#, C#.NET, WindowsForms, .NET Framework, VS2005, Visual Studio, XAML, WinFX, Windows Workflow, WPF, WCF, Atlas, NetFX3, Visual Studio Orcas"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="4997399242"; google_color_border = "B6C9E7"; google_color_bg = "EFEFEF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "002C99"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<!--
-->

You should feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever. That said, I will most likely only delete abusive, profane, rude, or annonymous comments, so keep it polite, please.

Blogroll

Cool .NET Articles

My .NET Tools

My Builder.com Articles

My MSKB Articles

Dynamic Registry Installer Class

I wrote some simple yet effective code last night. Since I can't put it in the Interscape Base Library, I'm making it available here. Have at it:

Imports System.ComponentModel
Imports
System.Configuration.Install
Imports Microsoft.Win32

Namespace Installers

    <RunInstaller(
True
)> _
    Public Class
Installer
       
Inherits
System.Configuration.Install.Installer

        #Region " Component Designer generated code "

        Public Sub New()
            MyBase
.New()
           
'This call is required by the Component Designer.
           
InitializeComponent()
           
'Add any initialization after the InitializeComponent() call
       
End
Sub

       
'Installer overrides dispose to clean up the component list.
       
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean
)
           
If disposing
Then
               
If Not (components Is Nothing)
Then
                   
components.Dispose()
                End
If
           
End
If
           
MyBase
.Dispose(disposing)
       
End
Sub

       
'Required by the Component Designer
       
Private components As
System.ComponentModel.IContainer
       
'NOTE: The following procedure is required by the Component Designer
       
'It can be modified using the Component Designer.
       
'Do not modify it using the code editor.
       
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
            components =
New
System.ComponentModel.Container
       
End Sub

        #End Region

       
Public Overrides Sub Install(ByVal stateSaver As
System.Collections.IDictionary)
           
MyBase
.Install(stateSaver)
            
' Gets the parameter passed across in the CustomActionData.
           
Dim KeyName As String = Me
.Context.Parameters.Item("Key")
           
Dim Location As String = Me
.Context.Parameters.Item("Location")

           
If KeyName = "" Then Throw New
InstallException("The Registry key was not specified. The Registry could not be modified.")
           
If Location = "" Then Throw New
InstallException("The Path was not specified. The Registry could not be modified.")
       
           
Dim regKey As
RegistryKey
            regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETFramework\AssemblyFolders",
True
)
            regKey.CreateSubKey(KeyName)
            regKey.SetValue("", Location)
            regKey.Close()
       
End
Sub

       
Public Overrides Sub Uninstall(ByVal stateSaver As
System.Collections.IDictionary)
           
MyBase
.Uninstall(stateSaver)
           
' Gets the parameter passed across in the CustomActionData.
           
Dim KeyName As String = Me
.Context.Parameters.Item("Key")
           
Dim Location As String = Me.Context.Parameters.Item("Location")

           
If KeyName = "" Then Throw New InstallException("The Registry key was not specified. The Registry could not be modified.")
           
If Location = "" Then Throw New InstallException("The Path was not specified. The Registry could not be modified.")

           
Dim regKey As RegistryKey
           
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETFramework\AssemblyFolders", True)
           
regKey.DeleteSubKey(KeyName)
           
regKey.Close()

       
End Sub

   
End Class

End
Namespace

Now, all you do after this is add your assembly to the custom actions, 2 times for the Install and the Uninstall (4 total), and set the custom data to read: /Key=Interscape.1.0.3300.0 /Location=[TARGETDIR]\v2.0\Redistributable\For .NET 1.0 and /Key=Interscape.1.0.5000.0 /Location=[TARGETDIR]\v2.0\Redistributable\For .NET 1.1 respectively. Those examples are from Interscape's Base Library, of course, but you can see how it would work. Do the same thing for the Uninstall routine, and you're golden.

I think I need to build a tool for writing installer project templates...

Comments

Eduard Witteveen said:

> Now, all you do after this is add your assembly
> to the custom actions, 2 times for the Install
> and the Uninstall (4 total)
And how would i do that :S
# July 28, 2004 9:54 AM