Solved

Change Access Rights to sub folder of CommonApplicationData\MyProgramName

Posted on 2013-06-28
12
803 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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 80

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Adding Existing Item to vb.net Project causes Errors 4 43
Help with converting xml file to excel using VB.NET 3 25
VB.NET 2008 Publish Error 2 33
How to limit User Input 2 27
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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