Introduction
Often, developers receive access rights errors while installing
application in Windows 7 and Vista.
The error message will typically look like "Access to the path is denied".


Solution
- Find the current execution folder
- Find all files in the folder recursively
- Set Full Access Rights to all the files
The application is named as SetAccessRights.exe.
Modifying the Setup Application
In the following window, choose Add Custom Action from the Commit node.
In the appearing dialog box, select the Primary output from the SetAccessRights
file. Then select the added file and change the property InstallerClass to false
as shown below.
Now build the setup and execute it. After installation, run the FolderRights.exe
from the installed folder in Program Files. Click the Write button on the
executable and this time no error message will be shown.
You can open the File.txt and see the appended data.
The attached source code contains the main application, setup application,
access rights setter application. You can execute the setup and see the results.
The core method providing full access rights is shown below:
Modifying the Setup Application
For calling the above SetAccessRights.exe, we need to set custom actions in the
setup application. For this, right-click on the setup and choose Custom Actions.




Code Attached
- private void SetAccessRights(string file) {
- FileSecurity fileSecurity = File.GetAccessControl(file);
- AuthorizationRuleCollection rules = fileSecurity.GetAccessRules(true, true, typeof(NTAccount));
- foreach(FileSystemAccessRule rule in rules) {
- string name = rule.IdentityReference.Value;
- if (rule.FileSystemRights != FileSystemRights.FullControl) {
- FileSecurity newFileSecurity = File.GetAccessControl(file);
- FileSystemAccessRule newRule = new FileSystemAccessRule(name, FileSystemRights.FullControl, AccessControlType.Allow);
- newFileSecurity.AddAccessRule(newRule);
- File.SetAccessControl(file, newFileSecurity);
- }
- }
- }


Mageshwaran RPosted Nov 25, 2019, 3:05 AM
Nice Article...
Sourav Kumar DasPosted Nov 24, 2019, 11:03 PM
Nice Article Sir.
Anas ZetaPosted Mar 7, 2016, 3:42 PM
Jean - Thanks so much for this great project
Antony JPosted Jan 13, 2016, 9:22 AM
Hi I'm Anto. I used your code which is working fine.. But which is working in all the drives except program files (*86) folder. My setup will install in the program files (*86) folder. I'm using C# with SQLITE DB. I couldnot insert the records or open the database. If i manually give the permission to the folder which is working. But i need to give the rights permission through the coding when installation or after installation. PLs let me know the solution. I'm using Windows 7 and VS2008. Thanking You!..
m zPosted Oct 13, 2014, 3:34 PM
very very thank you
Harshal ThakrePosted Jun 26, 2014, 8:15 AM
thanks sahi me bahut super
Muthu KumarPosted Oct 24, 2013, 9:28 AM
Hi shankar, the same i need u posted if u get solution pls let me know I am working on Auto Updater Where I need Permission to move a file to the installed location. Please help me how we provide rights to the folder so I will be able to move a file to the executable loation.. I you did not get my question I will elaborate
Jean PaulPosted Oct 18, 2013, 12:47 AM
Thank You Shankar! :)
Kalaivanan shanmugamPosted Oct 17, 2013, 8:39 AM
Am getting error i.e Error 1001 Could not find the file 'C:\Program files\SetaccessRight.installState.How to resole this please tell me
Jean PaulPosted Jan 6, 2013, 8:44 AM
Thank You Prasanna!
Prasanna LenadoraPosted Jan 6, 2013, 2:24 AM
Excellent! This is what I have been looking for.
Prasanna LenadoraPosted Jan 6, 2013, 2:24 AM
Excellent! This is what I have been looking for.
Prasanna LenadoraPosted Jan 6, 2013, 2:24 AM
Excellent! This is what I have been looking for.
Jean PaulPosted Dec 3, 2012, 12:16 PM
You are welcome my dear friend!
pccong2002Posted Dec 3, 2012, 10:46 AM
thanks for your sharing.
Jean PaulPosted Nov 29, 2012, 10:04 AM
You are welcome Sumanth! Happy to hear that it helps you.
Sumanth MPosted Nov 29, 2012, 4:43 AM
H, Paul, This is the exact solution which i have been looking for. Thanks for posting such a good article.
Jean PaulPosted Sep 11, 2012, 9:30 AM
You are Welcome my dear Patel!
Paresh PatelPosted Sep 11, 2012, 3:00 AM
Very good. It's very helpful.. Thanks