Solved

Change Access Rights to sub folder of CommonApplicationData\MyProgramName

Posted on 2013-06-28
12
791 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
  • 9
  • 2
12 Comments
 
LVL 5

Expert Comment

by:truinx
Comment Utility
Try executing the code using Administrator rights.
0
 

Author Comment

by:Trampas_c
Comment Utility
How do I do that?
0
 
LVL 5

Expert Comment

by:truinx
Comment Utility
How is the script executed? On installation?
0
 

Author Comment

by:Trampas_c
Comment Utility
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
Comment Utility
the path is determined as

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

Author Comment

by:Trampas_c
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Trampas_c
Comment Utility
Currently installing free Limited Edition of InstallShield for VS2010
0
 

Author Comment

by:Trampas_c
Comment Utility
Now discovered DLL not included as Custom Action for free version
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
0
 

Author Comment

by:Trampas_c
Comment Utility
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
Comment Utility
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
Comment Utility
There is no solution to the question
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now