1

I'm new to winform programming and trying to generating exe setup file, for that I'm using MicrosoftVisualStudio2015InstallerProjects.

I've created .exe file and it's working fine, but after installation every time I need to go the installation directory and give permission to the user. To get rid out from this issue, I've tried to use AfterInstall event and give all permission to user.

public partial class ClientInstaller: Installer
{
   public ClientInstaller() : base()
   {
       AfterInstall += new InstallEventHandler(AfterInstallEventHandler);
   }
}

private void AfterInstallEventHandler()
{       
    string appPath = Path.GetDirectoryName(Application.StartupPath);

    DirectoryInfo dInfo = new DirectoryInfo(appPath);
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
    dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
    dInfo.SetAccessControl(dSecurity);
} 

But seems like event not fired after installation. Then I tried to override OnAfterInstall

public partial class ClientInstaller: Installer
{
   protected override void OnAfterInstall(IDictionary savedState)
   {
       base.OnAfterInstall(savedState);
       // Add steps to be done after the installation is over.
       Console.WriteLine("OnAfterInstall method of MyInstaller called");
   }
}  

Though it's not showing me console(changed target to console).

Am I missing something here?

Hina Khuman
  • 757
  • 3
  • 14
  • 41

0 Answers0