Test Case 15: Verify application installs to the correct folders by default (Req:2.3)

Default install directories are:

Ø       Native x86 and x64 applications

o        Program Files - %ProgramFiles%

o        User’s AppData - %APPDATA%

o        ProgramData – %ALLUSERSPROFILE%

Ø       Win32 applications on x64

o        Program Files - %ProgramFiles(x86)%

o        AppData - %APPDATA%

o        ProgramData – %ALLUSERSPROFILE%

 

Question: Where to store read/write data for all users?

Answer: The suggestion for you is to use the ProgramData (%ALLUSERSPROFILE%) folder (e.g, create ProgramData\<Company>\<Product>) and update the Access Control List (ACL) according to your requirement, during install. The MSDN resource Per-machine Installations at http://msdn2.microsoft.com/en-us/library/aa370810.aspx should be helpful to you.

 

So, if it is ever changing shared DATA (not CODE) then it should logically go in to ProgramData folder. If it is individual DATA then it can go to the user profile. This is suggested with couple of other aspects like security in consideration.

 

Question: How can I change ACL?

Answer: You can refer to the following code snippet to use the DirectorySecurity class to update ACL.

 

private void UpdateACL()

{

     string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyProgramData");

     try

     {                                                                                      

        System.IO.Directory.CreateDirectory(folderPath);

        System.IO.DirectoryInfo di = new DirectoryInfo(folderPath);

        DirectorySecurity ds = new DirectorySecurity();

        FileSystemAccessRule fACL = new FileSystemAccessRule("MyUser", FileSystemRights.ReadAndExecute,

InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow); // Please choose the parameters here as per requirement

        ds.SetAccessRule(fACL);

        di.SetAccessControl(ds);

        MessageBox.Show("Folder " + folderPath + " created and updated ACL");

     }

     catch (Exception ex)

     {

          MessageBox.Show("Could not create folder in ProgramData folder.\nReason: " + ex.Message);

     }

}