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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to Remove Sharing Permission of a Folder through c#

How to Remove Sharing Permission of a Folder through c#

Scheduled Pinned Locked Moved C#
csharpsecuritytutorial
2 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.
  • H Offline
    H Offline
    himuskanhere
    wrote on last edited by
    #1

    Hello Friends, I want to search a folder which is shared to "EveryOne", with its FileSyatemRigths. I have a code:

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share");
    foreach (ManagementObject share in searcher.Get())
    {
    string path = share["Path"].ToString();

                    DirectoryInfo di = new DirectoryInfo(path);
                    DirectorySecurity ds =  di.GetAccessControl();
                                    
                    DirectorySecurity myDirectorySecurity = di.GetAccessControl();
                  AuthorizationRuleCollection arc =  myDirectorySecurity.GetAccessRules(true,true,typeof(System.Security.Principal.NTAccount));
                    
                    myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule("EveryOne", FileSystemRights.FullControl , AccessControlType.Allow));
                                        //di.SetAccessControl(myDirectorySecurity);
                                        
                    }
    

    It gives me the all shared folder and tried to remove Sharing permission. But it fails i)if Sharing is not given to EveryOne ii) If sharing is given to EveryOne but other than full control. "Please suggest a way to retrive sharing folder having access given to Every one and then how to remove that access irrespective of Access Permisssion" Thanks in advance:cool:

    M 1 Reply Last reply
    0
    • H himuskanhere

      Hello Friends, I want to search a folder which is shared to "EveryOne", with its FileSyatemRigths. I have a code:

      ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share");
      foreach (ManagementObject share in searcher.Get())
      {
      string path = share["Path"].ToString();

                      DirectoryInfo di = new DirectoryInfo(path);
                      DirectorySecurity ds =  di.GetAccessControl();
                                      
                      DirectorySecurity myDirectorySecurity = di.GetAccessControl();
                    AuthorizationRuleCollection arc =  myDirectorySecurity.GetAccessRules(true,true,typeof(System.Security.Principal.NTAccount));
                      
                      myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule("EveryOne", FileSystemRights.FullControl , AccessControlType.Allow));
                                          //di.SetAccessControl(myDirectorySecurity);
                                          
                      }
      

      It gives me the all shared folder and tried to remove Sharing permission. But it fails i)if Sharing is not given to EveryOne ii) If sharing is given to EveryOne but other than full control. "Please suggest a way to retrive sharing folder having access given to Every one and then how to remove that access irrespective of Access Permisssion" Thanks in advance:cool:

      M Offline
      M Offline
      Md Marufuzzaman
      wrote on last edited by
      #2

      Try this link.[^] I hope this might be helpful to you.

      Thanks Md. Marufuzzaman


      I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

      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