Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > Custom Action While Installing Setup file
 

Custom Action While Installing Setup file

Hi,

I am creating a Setup.exe file using setup and deployment project for my C#.NET application. While Installing I need to check a folder in C: drive and if it exists, I need to delete the folder. How to do such custom actions while installing?

Regards,
Sanjeevi
San1984  Monday, August 31, 2009 7:58 AM

Hi,

You can use custom actions to run code at the end of a Windows Installer installation to perform actions that cannot be handled during installation. (From http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx )

By the way, do you mean you want to check whether installation folder exists? You can select a folder in select installation folder form.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 07, 2009 7:34 AM
Hi Ling Wang,

Thanks for the reply! After a long time, I could see some response here.

I gone through that link. I have also gone through some of the aricles available in web. But I coul'nt do any custom actions while installing.

Please see the code snippet of the installer class.

using

System;

using

System.Collections.Generic;

using

System.Text;

using

System.ComponentModel;

using

System.Configuration.Install;

using

System.Collections;

using

System.IO;

using

System.Diagnostics;

namespace

SynapseInstallerClassLibrary

{

[

RunInstaller(true)]

public partial class Installer1 : Installer

{

public Installer1()

{

InitializeComponent();

this.Committed += new InstallEventHandler(Installer1_Committed);

}

public override void Install(IDictionary stateSaver)

{

base.Install(stateSaver);

}

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

public override void Uninstall(IDictionary savedState)

{

base.Uninstall(savedState);

}

private void Installer1_Committed(object sender,

InstallEventArgs e)

{

string strPath = "C:\\Program Files\\Sanjeevi";

try

{

if (Directory.Exists(strPath))

{

Directory.Delete(strPath);

}

}

catch (Exception)

{

throw;

}

}

}

}

San1984  Monday, September 07, 2009 2:13 PM
Depends what you mean by "while installing". If you want to delete that folder before anything is copied you're not going to be able to do that with a custom action because they run after the install, after your files have been installed.
Phil Wilson
PhilWilson  Tuesday, September 08, 2009 7:44 PM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, September 13, 2009 9:04 AM

You can use google to search for other answers

Custom Search

More Threads

• Web Publishing with multiple connection strings
• ALLUSERS Property
• Can I change duration to ask again whether update/skip?
• How to automatically update an application using Windows Installer
• For some custromers, ClickOnce deployment repeatedly failing part way through.
• Deployment project - how do I get a link to my executable within the start>Program Files menu?
• Why both an Setup.exe and an MSI?
• install msi file with setup
• Unknown Deployment Server During Bootstrapper Construction
• Configuring .NET Applications to Run