26284 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: May 31
May Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
VMware public cloud
aims at ESXi
customers, not AWS
Microsoft reveals
Xbox One, the
console that can
read your heartbeat
New Intel CEO
Krzanich takes
reins of core
product groups
CSIRO scales up
solar cell printing
Cook: Apple has "no
current plan" to
pull profits out of
Ireland
AWS cloud gains
critical federal
security
certification
IBM puts
supercomputer
Watson to work in
ROBOT CALL CENTRE
Irish deputy PM:
You want more tax
from Apple? Your
problem, not ours
Private equity firm
coughs £1bn for
Websense
Violin welcomes new
grand master flash
flogger
Slashdot
EPA Makes a Rad
Decision
Ask Slashdot: Can
Yahoo Actually
Stage a Comeback?
3-D Printable Food
Gets Funding From
NASA
Transporting a
15-Meter-Wide,
600-Ton Magnet
Cross Country
House Bill Would
Mandate Smart Gun
Tech By U.S.
Manufacturers
Do Developers Need
Free Perks To
Thrive?
So You"ve Always
Wanted a
Hovercraft...
(Video)
Microsoft Unveils
Xbox One
Ask Neil Gaiman and
Amber Benson About
Their Kickstarter
Vampire Movie
Immigration Reform
May Spur Software
Robotics
Article viewer

Advanced .NET MSI handling



Written by:bb
Published by:thinkt4nk
Published on:2004-06-14 10:25:54
Topic:Dot.Net
Search OSI about Dot.Net.More articles by bb.
 viewed 18229 times send this article printer friendly

Digg this!
    Rate this article :
This article describes how to get access to variables used during an MSI installation process in .NET by extending the System.Configuration.Install.Installer class.

Often you need to get access to variables created during the installation process. One of the most common being the installation path or 'TARGETDIR'. This can be done by performing two steps.

Step one

In your deployment project, press the right mouse button on the project in the class view and select Custom Actions. You should see the four default states for the installer. Select the primary output for the Commit state.

In the properties window there is a property named CustomActionData, here you use name value pairs to define data to be accessible in your program. Setting the following property creates a variable named DIR with the target folder within it (Remember to include quotes as the path may contain spaces). This example also includes a trailing slash.
/DIR="[TARGETDIR]"

You can add additional variables by separating the values with commas.


Step two

In order to access the variable and do something during the installation you need to create a class which inherits from System.Configuration.Install.Installer. The following is a class written in vb.net which extends the commit of the installer to save a record in the registry of the target directory the app was installed to.

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

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

Dim strInstallLocation As String

Public Overrides Sub Commit(ByVal savedState As IDictionary)
    MyBase.Commit(savedState)

    'get the install location
    strInstallLocation = Me.Context.Parameters.Item("DIR")
    
    If strInstallLocation = Nothing Then
        strInstallLocation = String.Empty
    
    Else
    
        'always set the install dir
        SetReportSettingsValue("InstallDir", strInstallLocation)

        End If
    End Try

End Sub

'default install function
Public Overrides Sub Install(ByVal savedState As IDictionary)
    MyBase.Install(savedState)
End Sub

'function to set a registry value
Public Shared Function SetReportSettingsValue(ByVal Key As String, ByVal Value As String)
    Dim RegKey As RegistryKey = Registry.LocalMachine
    RegKey = RegKey.OpenSubKey("SOFTWAREReportSettings", True)

    If Not RegKey Is Nothing Then
        RegKey.SetValue(Key, Value)
        RegKey.Close()
    End If
End Function

End Class

Heres some other useful urls on the subject.
Installer for a Windows Service
Exploiting .NET's Advanced Deployment Features

Did you like this article? There are hundreds more.

Comments:
Anonymous
2007-05-30 21:55:18
But can you SET the TargetDir rather than just read it? Thanks.
Anonymous
2009-04-22 08:59:27
Hello
Can you SET the TargetDir rather than just read it?
flash games
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
bb
ASP.NET RadioButton GroupName when inside a Repeater on Sun 10th Jun 8am
I was thankful on finding this nugget of code, which makes the groupname work out when slamming in radiobuttons in an asp.net repeater. http://www.codeguru.com/csharp/csharp/cs _controls/custom/article.php/c12371/


     
Your Ad Here
 
Copyright Open Source Institute, 2006