Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change Access Rights to sub folder of CommonApplicationData\MyProgramName

Posted on 2013-06-28
12
Medium Priority
?
837 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 84

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

926 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