Solved

Change Access Rights to sub folder of CommonApplicationData\MyProgramName

Posted on 2013-06-28
12
810 Views
Last Modified: 2013-07-17
I need to change permissions on my applications sub folder of CommonApplicationData\MyProgram so that all users can read/write to an Access mdb file in the folder

This code needs to be in my install project for which I have created a Custom Action DLL

Try as I might I cannot seem to get my code to change the access rights for all users/everyone.

I have tried the code below but it does not change the permissions

    Private Sub UpdateSecurity2(ByVal FolderPath As String)


        Dim domainSid As New SecurityIdentifier("S-1-0-0")
        Dim Users As New SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, domainSid)

        If Directory.Exists(FolderPath) Then
            ' Get a DirectorySecurity object that represents the  current security settings.
            Dim dSecurity As DirectorySecurity = Directory.GetAccessControl(FolderPath, AccessControlSections.Access)

            ' Create a new rule (directories must have Object inheritance)
            Dim accessRule As New FileSystemAccessRule(Users, FileSystemRights.Modify, InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow)

            ' Add the FileSystemAccessRule to the security settings
            dSecurity.AddAccessRule(accessRule)

            ' write the new access settings
            Directory.SetAccessControl(FolderPath, dSecurity)
        End If
    End Sub

I did find some code here but it is not VB and needs translating

http://www.codeproject.com/Tips/61987/Allow-write-modify-access-to-CommonApplicationData
0
Comment
Question by:Trampas_c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 2
12 Comments
 
LVL 5

Expert Comment

by:truinx
ID: 39283916
Try executing the code using Administrator rights.
0
 

Author Comment

by:Trampas_c
ID: 39283924
How do I do that?
0
 
LVL 5

Expert Comment

by:truinx
ID: 39283941
How is the script executed? On installation?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:Trampas_c
ID: 39283947
The script is part of a custom action dll which copies the database files from the install CD to a folder under 'Program Data' in the case of Windows 7

The install has to be done by an administrator
0
 

Author Comment

by:Trampas_c
ID: 39283961
the path is determined as

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToString & "\MyAppName"
0
 

Author Comment

by:Trampas_c
ID: 39283982
Found this http://msdn.microsoft.com/en-us/library/windows/desktop/aa368073(v=vs.85).aspx

It says that custom actions only run with normal user rights
0
 

Author Comment

by:Trampas_c
ID: 39284075
Currently installing free Limited Edition of InstallShield for VS2010
0
 

Author Comment

by:Trampas_c
ID: 39284262
Now discovered DLL not included as Custom Action for free version
0
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 39286318
0
 

Author Comment

by:Trampas_c
ID: 39289624
Ve3ofa

Looked at code above and incorporated into my custom action DLL. The code was similar to what I had but with the various tweeks mentioned.

I then recompiled my install and tested on a  Win 7.

I installed as an adminstrator user and entered some data.
Switched to a standard user and the data not there i.e different/user specific.

I then added the code from above link (Public Function ListDirectoryACLs) to the main program exe itself to report what security was on my ProgramData\MyApp folder to a message box, and ran the main exe on the Win7  machine.

This caused the standard windows security message to ask if I wanted to make changes on the PC (strange as all i am doing is listing the access rights not making changes)

Then I switched to the standard user and ran the program and again I got the same message before the message box appeared.

Odd thing is though, the data is now all being shared by both users, but only if I list the security on the folder???

I then returned to the install DLL and inserted the code to list the access rights but not show the message box just in case for some odd reason this made the exe share the same data file after installation.

Result after re-installing was both users were no longer sharing data.

So, If I add some code to list the access rights, I get a message to modify the computer regardless of who is logged on (standard or Admin user) and the data file is shared.

This all just getting crazy!

I think I am going to have to abandon using ProgramData for shared program data. Its obviously only meant for ProgramData for one user. I'll have to just make a folder on the C drive and check that it is being shared.

I don't think there is a solution to UAC. Special folders indeed!
0
 

Accepted Solution

by:
Trampas_c earned 0 total points
ID: 39320532
Summary to this is that the special folder ProgramData is meant to host data for multiple users, but only so far as they can all get a copy of the original data file for the program to work. After that they all start updating their own virtual copy. The only way to share data seems to be if the data is on a server or the database is SQL server on the PC and not Microsoft Access. Trying to alter the security also resulted in dozens of nested copies of the ProgramData folder. So the answer to my question is it is no longer possible to share data on a windows 7 PC using Microsoft Access files that are stored on the PC if UAC is enabled.
0
 

Author Closing Comment

by:Trampas_c
ID: 39332600
There is no solution to the question
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question