Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. change directory access control for common application data folder failed.

change directory access control for common application data folder failed.

Scheduled Pinned Locked Moved C#
help
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CooperWu
    wrote on last edited by
    #1

    Here is my code, and i tried same code for file access control, it works well. but doesn't work for common application data on Vista.

    private static void GrantEveryoneFullControlRight(string directory)
            {
                try
                {
                    if (!Directory.Exists(directory))
                        Directory.CreateDirectory(directory);
    
                    DirectoryInfo dirInfo = new DirectoryInfo(directory);
                    DirectorySecurity ds = dirInfo.GetAccessControl(AccessControlSections.Access);
    
                    FileSystemAccessRule rule = new FileSystemAccessRule(
                        "Users", FileSystemRights.FullControl, AccessControlType.Allow);
    
                    ds.AddAccessRule(rule);
                    dirInfo.SetAccessControl(ds);
    
    
                }
                catch (Exception ex)
                {
                    // Logger.WriteLog(LogType.Error, ex.ToString());
                    Console.WriteLine(ex.ToString());
                }
            }
    

    Glad to discuss with you and best wishes.

    C 1 Reply Last reply
    0
    • C CooperWu

      Here is my code, and i tried same code for file access control, it works well. but doesn't work for common application data on Vista.

      private static void GrantEveryoneFullControlRight(string directory)
              {
                  try
                  {
                      if (!Directory.Exists(directory))
                          Directory.CreateDirectory(directory);
      
                      DirectoryInfo dirInfo = new DirectoryInfo(directory);
                      DirectorySecurity ds = dirInfo.GetAccessControl(AccessControlSections.Access);
      
                      FileSystemAccessRule rule = new FileSystemAccessRule(
                          "Users", FileSystemRights.FullControl, AccessControlType.Allow);
      
                      ds.AddAccessRule(rule);
                      dirInfo.SetAccessControl(ds);
      
      
                  }
                  catch (Exception ex)
                  {
                      // Logger.WriteLog(LogType.Error, ex.ToString());
                      Console.WriteLine(ex.ToString());
                  }
              }
      

      Glad to discuss with you and best wishes.

      C Offline
      C Offline
      CooperWu
      wrote on last edited by
      #2

      nobody know how to solve this? :sigh: :sigh: :(( :((

      Glad to discuss with you and best wishes.

      B 1 Reply Last reply
      0
      • C CooperWu

        nobody know how to solve this? :sigh: :sigh: :(( :((

        Glad to discuss with you and best wishes.

        B Offline
        B Offline
        brian598
        wrote on last edited by
        #3

        I do something very similar except use "Everyone" in the access rule: string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string _localUserDataPath = Path.Combine(appDataPath,"My Company\\MyApp\\"); if (!Directory.Exists(_localUserDataPath)) { DirectorySecurity ds = new DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); Directory.CreateDirectory(_localUserDataPath, ds); } else { // the directory exists - lets change security on it DirectoryInfo di = new DirectoryInfo(_localUserDataPath); DirectorySecurity ds = new System.Security.AccessControl.DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(ds); }

        C 1 Reply Last reply
        0
        • B brian598

          I do something very similar except use "Everyone" in the access rule: string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string _localUserDataPath = Path.Combine(appDataPath,"My Company\\MyApp\\"); if (!Directory.Exists(_localUserDataPath)) { DirectorySecurity ds = new DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); Directory.CreateDirectory(_localUserDataPath, ds); } else { // the directory exists - lets change security on it DirectoryInfo di = new DirectoryInfo(_localUserDataPath); DirectorySecurity ds = new System.Security.AccessControl.DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(ds); }

          C Offline
          C Offline
          CooperWu
          wrote on last edited by
          #4

          does this work on Vista?

          Glad to discuss with you and best wishes.

          B 1 Reply Last reply
          0
          • C CooperWu

            does this work on Vista?

            Glad to discuss with you and best wishes.

            B Offline
            B Offline
            brian598
            wrote on last edited by
            #5

            Well, I thought it was working on Vista but I must have been running my client in admin mode because I can't get it to work again. What does work is creating an installer package for my windows service that creates the directory in ProgramData. Using vs.net 2008 I added a custom folder called Common Application Data Folder (any name will work). I set the DefaultLocation property to [CommonAppDataFolder] and the Property property to COMMONAPPDATAFOLDER. Then I added my own folders to this folder (Company\commondir). When the install is run it creates the folders and adds "Users" to the security properties for those folders. This seems to give "Users" enough permission to read/execute and write files to that location. My non-admin windows client can read/ write and execute from the folder and my windows service can as well.

            C 1 Reply Last reply
            0
            • B brian598

              Well, I thought it was working on Vista but I must have been running my client in admin mode because I can't get it to work again. What does work is creating an installer package for my windows service that creates the directory in ProgramData. Using vs.net 2008 I added a custom folder called Common Application Data Folder (any name will work). I set the DefaultLocation property to [CommonAppDataFolder] and the Property property to COMMONAPPDATAFOLDER. Then I added my own folders to this folder (Company\commondir). When the install is run it creates the folders and adds "Users" to the security properties for those folders. This seems to give "Users" enough permission to read/execute and write files to that location. My non-admin windows client can read/ write and execute from the folder and my windows service can as well.

              C Offline
              C Offline
              CooperWu
              wrote on last edited by
              #6

              Thanks for your reply, we granted directory access right in installer too. It works well. :laugh: :laugh:

              Glad to discuss with you and best wishes.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups