0

the below is a sample custom installer class.

[RunInstaller(true)]
public  partial class Installer1 : System.Configuration.Install.Installer
{
    public Installer1()
    {
        InitializeComponent();
    }
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        // Do your magic here, call your form, do your thing...

    }
 [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {

        base.Commit(savedState);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Rollback(IDictionary savedState)
    {
        // if something goes wrong, it's here you correct it and rollback the system to its previous state and undo what you already changed
        base.Rollback(savedState);
    }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            // Here you undo changes when you cancel
            base.Uninstall(savedState);
        }

    }

now i want to design my apps in such a way when user will try to install my apps then a dialog comes and will ask for credential. if user will not be able to give right credentials then my apps will not be installed in user pc.

the same way if user will not be able to provide credentials during uninstallation then user will not be able to uninstall my apps.

please guide me how could prevent install and uninstall action from custom install class. thanks

Mou
  • 15,673
  • 43
  • 156
  • 275
  • Check [this](http://stackoverflow.com/questions/19537248/showing-custom-form-before-installation/19588180#19588180) post. – Kurubaran Apr 06 '15 at 13:27
  • @ Kurubaran : thanks for the link but from there i noticed that they throw exception when credentials is not right but i do not want to throw exception rather i want to show a message like "Invalid credentials" and stop user to move forward to install the apps.........is it possible? – Mou Apr 06 '15 at 13:58
  • What should happen when user insert invalid password ? do you want to stay on the same window until user insert right password or rollback the installation ? – Kurubaran Apr 06 '15 at 14:05
  • if user input wrong credentials then i like to show a message and close the installation window. – Mou Apr 06 '15 at 14:30

1 Answers1

0

Installer classes only run in the execute sequence and aren't designed for displaying UI. Also installers are very transparent and easy to transform to defeat this mechanism. I suggest moving this into application logic at runtime or using a windows installer authoring tool that allows you to customize the UI sequence (proper design but still hackable).

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • thanks for reply. can u plzz discuss in more detail. – Mou Apr 07 '15 at 07:23
  • There isn't much more detail. All VS install custom actions run after all the files are installed, so it's too late to stop the install. I think Chris is saying "who cares about the install"? Just require the app to ask for credentials on its first run. That's more secure than an MSI file. Anything you do to try to prevent uninstall from the MSI will be hackable because MSI files are transparent, and it seems unusual to prevent uninstall like that - you could drive IT managers and admins crazy trying to manage systems. – PhilDW Apr 07 '15 at 18:02
  • Ah... uninstall. Missed that. So use ARPSYSTEMCOMPONENT and write your own EXE to launch uninstall after the proper password check. – Christopher Painter Apr 07 '15 at 18:07