1

I have made an installer which contains the exe and dlls, made in using Visual studio the thing is can i add some code to it?

example when it install i just want to run 3-4 lines of code.

1- Get mac address add to database, with a unique key.

And similarly on uninstall remove the mac address from the database .

Is this possible in this current scenario using the default setup project?

4
  • Which mac address? Machines may have multiple network adapters (both real and virtual) and they'll all have different addresses. And it's still possible that someone may replace a network adapter, so changing one or more mac addresses. Jan 16, 2013 at 15:22
  • @Damien_The_Unbeliever getting the mac address in not mainly my concern it was just to add code to the installer. Jan 16, 2013 at 15:34
  • I was just trying to point out that, if you've split this problem down into "get mac address, then add/remove it to a database at appropriate installation times", and you're concentrating on part 2 at the moment, you're currently ignoring a bigger issue for why this solution may not work. Jan 16, 2013 at 15:36
  • @Damien_The_Unbeliever i wont be using mac it was just an example :), will use keys generated on runtime something like that. Jan 16, 2013 at 15:39

2 Answers 2

2

You will need to use a CustomAction for your installer. With this you can run a program, script, write a registry key, or whatever. Here's a simple example using a custom installer class to show a message during the installation (in VB.NET but easily translatable):

Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
  MyBase.Install(stateSaver)
  Dim myInput As String = Me.Context.Parameters.Item("Message")
  If myInput Is Nothing Then
    myInput = "There was no message specified"
  End If
  MsgBox(myInput)
End Sub

You would need to follow the steps in the link to fully reproduce the sample.

1
0

You could use the .NET installer classes and wire those up from the default setup project. You override some methods and then they get called at install/uninstall time. Here's a tutorial on how to do this.

That said, a lot of people hate these .NET installer classes (and the default setup projects) altogether and implement true Custom Actions using a WIX or InstallShield based project.

Depending on what exactly you want to do and when you want to do it, you also introduce a .NET dependency. For example, if you are checking for .NET being installed, you won't be able to do this from a .NET custom action if the user does not have .NET already installed.

Adding Custom Actions is a bit of a slippery slope. Once people realize you can customize the installer, you'll likely be asked to do more and more. At that point it may make sense to use a more flexible tool (WIX (open source) or InstallShield ($)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.