How to set a folder to Full Rights permission in Windows 7


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".
The same setup executed in a Windows XP machine will work fine, so the reason behind the above error is probably due to User Access Control changes in the Windows 7 and Vista operating systems. The changes are documented in MSDN.
You can view the user access level after installing the application.
You can see that the Full Control, Modify, and Write permissions are unchecked for the logged-in user. In this case, any attempt to modify the file will throw an exception.


We can approach the problem by using a customer installer action. After committing the installation, a custom executable is launched, which will take care of providing all permissions to the file.
The new executable could be a console application which will perform the following:
  • 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

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.
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.

Code Attached

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:
  1. private void SetAccessRights(string file) {    
  2.  FileSecurity fileSecurity = File.GetAccessControl(file);    
  3.  AuthorizationRuleCollection rules = fileSecurity.GetAccessRules(truetruetypeof(NTAccount));    
  4.  foreach(FileSystemAccessRule rule in rules) {    
  5.   string name = rule.IdentityReference.Value;    
  6.   if (rule.FileSystemRights != FileSystemRights.FullControl) {    
  7.    FileSecurity newFileSecurity = File.GetAccessControl(file);    
  8.    FileSystemAccessRule newRule = new FileSystemAccessRule(name, FileSystemRights.FullControl, AccessControlType.Allow);    
  9.    newFileSecurity.AddAccessRule(newRule);    
  10.    File.SetAccessControl(file, newFileSecurity);    
  11.   }    
  12.  }    
  13. }    
The core class in which the whole functionality included is: AccessRightsProvider.cs


In this article, we have seen the user access rights issue associated with setup installation in Windows 7 and the solution.