Installer package that modifies the security permissions of a file.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
BH
Hi
Im trying to create a setup project that modifies permissions of specific file during the installation process. Ive created an "Installer Class" and below is my code for the class. However, when i run the installation i get an exception. What
am i doing wrong?


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Windows.Forms;
using System.Security.AccessControl;
using System.Text;
using System.IO;

namespace FolderPermissions
{
[RunInstaller(true)]
public partial class Installer1 : Installer
{
public Installer1()
{
{

InitializeComponent();
//MessageBox.Show("hj");

string fileName = "ambtrans4.mdb";

// Console.WriteLine("Adding access control entry for "
// + fileName);

// Add the access control entry to the file.
AddFileSecurity(fileName, @"Everyone",
FileSystemRights.ReadData, AccessControlType.Allow);
AddFileSecurity(fileName, @"Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
MessageBox.Show("Security settings changed");
}

}

// Adds an ACL entry on the specified file for the specified account.
public static void AddFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{


// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);

// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));

// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);

}

}
}


thanks so much.
Aron
<hr class="sig Thanks Aron www.EvidenceForTorah.comxa.com

View the full article
 
Back
Top