C# Custom Actions - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

kirankunnam
Posts: 10
Joined: Thu Sep 29, 2011 5:50 am

C# Custom Actions

HI friends,

i'm new to this Advance Installer...

i'm facing one problem to add a custom actions.
i wrote a code in C# custom actions but i'm not getting the values from session.
here i need the values (The User Enter). so how can i get the user enter values. '

OR
can any body have any idea about in sending a mail and getting the values from installer using custom vc++ if there please send the code for that

please help me this ....

thanks,
kiran
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: C# Custom Actions

Hi Kiran and welcome to Advanced Installer forums,

Here is a sample function to help you with this:

Code: Select all

public static ActionResult CustomAction1(Session session)
{
// sending message to installation log
session.Log("Begin CustomAction1");

// getting a property
YourVariable = session["YOUR_PROPERTY"];

// setting a property
session["YOUR_PROPERTY"] = "YOUR_VALUE";

return ActionResult.Success;
}
As this can be achieved by using this user guide article, we will update it with this sample very soon.

In a Win32 DLL you can use the MsiGetProperty and MsiSetProperty functions for the same purpose.

I erased your other thread with identical title to keep everything organized under this one. Please provide your future feedback after trying our suggestions by posting here.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kirankunnam
Posts: 10
Joined: Thu Sep 29, 2011 5:50 am

Re: C# Custom Actions

hi mihai,

thanks for your reply..

but i wrote same code what you give ( string name = session["EDIT_1_PROP"].ToString();) but it's through a exception. that exception is already posted .. please look that error......

thanks
kiran
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: C# Custom Actions

Hi Kiran,

Here is how to debug your fully fledged( DTF ) C# custom action:
  • Add some code for displaying your message box at the beginning of your custom action. Something like this:

    Code: Select all

    public static ActionResult CustomAction1(Session session)
    {  
      // display message to allow attaching the debugger
      MessageBox.Show("Please attach a debugger to rundll32.exe.", "Attach");
      
      // sending message to installation log
      session.Log("Begin CustomAction1");
      .
      .
      .
    
  • Since you will use MessageBox, make sure you have a reference to System.Windows.Forms.dll
  • Add a breakpoint on the next line of code, after your message box code
  • Rebuild your custom action project with Visual Studio
  • Rebuild your Advanced Installer project
  • Run the installation using "Run and Log" from Advanced Installer
  • When the message box displays, go to Visual Studio project > Tools > Attach to Process…
  • From the Available Processes list select the process with the name "rundll32.exe" and title "Attach"
  • Click Ok on the message box in your installation
  • The breakpoint you set earlier should now be activated in VS
While debugging the custom action after implementing the above steps, you can observe the property changes in the Log pane of Advanced Installer.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kirankunnam
Posts: 10
Joined: Thu Sep 29, 2011 5:50 am

Re: C# Custom Actions

hi,
i'm following your process.

in that process i got this error.

Cannot access session details from a non-immediate custom action

so can you please send the details about that error.

if don't mind.

if this is not possiable please give the code for sending a mail and executing DB script using custom action in any other language like (vb.script and vc++)


thanks
kiran
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: C# Custom Actions

Hi kiran,

Installer properties can be accessed only by Immediate custom actions. So if your custom action is deferred, change it to Immediate.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”