0

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?

Alan
  • 2,046
  • 2
  • 20
  • 43
  • Are you running the installer with Admin rights or not on the Server machine? – Peter B Jun 08 '18 at 19:12
  • Why is your application storing configuration files inside Program Files? Sounds like in this case you should be using the All Users/Public User App Data directory for anything you want to use across all users that they can modify. If its your application and you're writing the setup then you should switch to doing that instead of trying to shoehorn it into Program Files. – PhonicUK Jun 08 '18 at 19:13
  • I am installing it with Admin rights, and the AppData directory isn't a bad solution, but does it actually solve the issue of the above code working on one system and not the other? – Alan Jun 08 '18 at 19:21
  • What is the exact value of `fullPath` on the server (don't guess, run the code and confirm)? Does the code throw any exceptions? – mjwills Jun 08 '18 at 21:27
  • I found out that NSIS has a plugin that helped me out: http://nsis.sourceforge.net/AccessControl_plug-in – Alan Jun 08 '18 at 21:50
  • If you know the answer, post it and then accept it. – Lex Li Jun 09 '18 at 02:17

0 Answers0