Monday, 30 July 2012

How To save common windows application setting locally for all users.

To save use config file. & create config file in programdata folder which common accessible for all user.
because of virtualization concept of win 7, normal standard user can not write that file.
so i have found one solution is
Assign everyone rights to that folder which is placed in programdata folder.
so any user can access & write that file.
to do this use below code.
 DirectoryInfo dInfo = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Procharge");  
 DirectorySecurity dSecurity = dInfo.GetAccessControl();  
 dSecurity.AddAccessRule(new FileSystemAccessRule("everyone",FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,PropagationFlags.InheritOnly,AccessControlType.Allow));  
 dInfo.SetAccessControl(dSecurity);  

No comments:

Post a Comment