Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The way to do it is to create a class derived from <code>System.Configuration.Install.Installer</code>. Override the <code>Install()</code> method. The following is an example that changes permissions on a directory and a file, you probably don't want to be so permissive, but it depends on your security context. In order for this to work, the setup project has to run this as a custom action. Add the "Primary Output" from whatever project this class is in. You will also need to pass the directory to the custom action in its properties. The first variable name has to match the code. Like this: <code>/targetdir="[TARGETDIR]\"</code></p> <pre><code>[RunInstaller(true)] public partial class SetPermissions : Installer { private const string STR_targetdir = "targetdir"; private const string STR_aspnetUser = "ASPNET"; public SetPermissions() { InitializeComponent(); } public override void Install(IDictionary stateSaver) { base.Install(stateSaver); Context.LogMessage( Context.Parameters .Cast&lt;DictionaryEntry&gt;() .Select(entry =&gt; String.Format("String = {0} Value = {1}", entry.Key, entry.Value)) .Aggregate(new StringBuilder("From install\n"), (accumulator, next) =&gt; accumulator.AppendLine(next)) .ToString() ); string targetDir = Context.Parameters[STR_targetdir]; string dbDir = Path.Combine(targetDir, "db"); AddFullControlPermissionToDir(dbDir, STR_aspnetUser); string rimdbSqliteFilename = Path.Combine(dbDir, "db.sqlite"); AddFullControlPermissionToFile(rimdbSqliteFilename, STR_aspnetUser); string logsDir = Path.Combine(targetDir, "logs"); AddFullControlPermissionToDir(logsDir, STR_aspnetUser); } private static void AddFullControlPermissionToDir(string dir, string user) { DirectorySecurity directorySecurity = Directory.GetAccessControl(dir); directorySecurity.AddAccessRule( new FileSystemAccessRule( user, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); Directory.SetAccessControl(dir, directorySecurity); } private static void AddFullControlPermissionToFile(string filename, string user) { FileSecurity fileSecurity = File.GetAccessControl(filename); fileSecurity.AddAccessRule( new FileSystemAccessRule( user, FileSystemRights.FullControl, AccessControlType.Allow)); File.SetAccessControl(filename, fileSecurity); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload