Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change Access Rights to sub folder of CommonApplicationData\MyProgramName

Posted on 2013-06-28
12
Medium Priority
?
828 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
Independent Software Vendors: 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!

 

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 83

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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