I have a Configuration.ini
file that is copied to the Program Files (x86)\myapp\
directory during install by the NSIS installer. When it is copied it doesn't have the permissions I need, so I tried changing it using the info from here:
How to grant full permission to a file created by my application for ALL users?
private void GrantAccess(string fullPath)
{
DirectoryInfo dInfo = new DirectoryInfo(fullPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
On my personal PC when developing it, the file gets permissions set, but when I deploy it to a Windows 2008 or 2012 server it isn't changing. There are 2 exe files that need to access / modify the settings, one is a service that runs as LocalSystem
, the other is just the local user.
Is there a more foolproof way that will work for all operating systems from Windows 7 up?