How to run .NET code upon installation? - 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!

Vilx-
Posts: 3
Joined: Thu Oct 09, 2008 3:26 pm

How to run .NET code upon installation?

Greetings!

I need to run some .NET code of my own creation sometime during the installation. I would also like my code to be able to log any error messages together with the rest of installer messages in the LOG file. After my code has executed, there is no point in keeping it on the computer, so the file should be deleted. How can I do this?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to run .NET code upon installation?

Hi,

What you need can be done by using a .NET Installer Class Action. However, I'm afraid that this type of custom actions cannot write in the installation log.
After my code has executed, there is no point in keeping it on the computer, so the file should be deleted.
This can be done by using a custom action. Please note that the User Guide contains the Remove a file or a folder during installation how-to which may help you. Note that another approach for removing a file is explained here.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Vilx-
Posts: 3
Joined: Thu Oct 09, 2008 3:26 pm

Re: How to run .NET code upon installation?

Thank you.

Unfortunately the logging is exactly why I'm having this problem. :( Without that I could just package my code in a .exe file and run is as an "Attached Custom Action".

Now, I did find an interesting workaround on the internet. One guy has written a simple native wrapper for .NET .DLL files - exactly for this purpose. It passes the MSI handle along to the .NET code which then imports native functions from msi.dll and can use all the installer features.

But there is a problem with this solution too. In "Attached Custom Action" I can specify only one .DLL file. That has to be the native .DLL. But this native .DLL then needs to load the .NET .DLL file. Is there any way to specify that the installer should extract two .DLL files and the run one of them (afterwards deleting them both)?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to run .NET code upon installation?

Hi,
Is there any way to specify that the installer should extract two .DLL files and the run one of them (afterwards deleting them both)?
I'm afraid that this cannot be done for attached custom actions. However, you can try using installed custom actions. Basically, you add the files in the "Files and Folders" page and then use one of them as a custom action. After the installation is finished, you can remove both files through another custom action.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Vilx-
Posts: 3
Joined: Thu Oct 09, 2008 3:26 pm

Re: How to run .NET code upon installation?

Hmm, well, I guess this might work. Thanks. :)

Return to “Common Problems”