Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Directory Security (http://www.programmingforums.org/showthread.php?t=13534)

PhilBon Jul 12th, 2007 12:31 AM

Directory Security
 
So Right now I'm working on Directory Security permissions. I have the following code:
:

  1.  
  2.         MsgBox("hi")
  3.         Dim myacc As New DirectorySecurity
  4.         myacc.AddAccessRule(New FileSystemAccessRule("MyUser", FileSystemRights.FullControl, AccessControlType.Allow))
  5. IO.Directory.CreateDirectory("Test",myacc)

Which creates a directory "Test" and then tries to set a new access control to it. The problem is the Directory Security settings has inherit on automatically, How do I turn that off? And by turning that off will it automatically allow me to do what I need it to do, being remove all the users and setting "MyUser" to be the only one with access to it? I also need to set the owner of the directory. I've just been working on it for about an hour and at the point of "giving" up until another time. UGH

Wizard1988 Jul 12th, 2007 1:03 AM

Is this of any help??

http://geekswithblogs.net/khanna/arc.../12/46033.aspx

john Wesley Jul 12th, 2007 9:06 AM

Yeah the chances are the directory should already exist - so if you create it, then alter access rules it should work, if you as the user running the program have the rights to do so.

try something like this, although its in C# should be easy to translate, if you need help tell me...

:

           
            DirectoryInfo di = Directory.CreateDirectory("Test");
            DirectorySecurity ds = di.GetAccessControl();
            ds.AddAccessRule(new FileSystemAccessRule(
                "MyUser", FileSystemRights.FullControl, AccessControlType.Allow)
            );


PhilBon Jul 12th, 2007 9:38 AM

@Wizard: That helps a little in the sense of looping through each of the User Permissions.
@John: Thats what I had before and it would not work, as well as you are missing the part where you apply the access rules to the folder.

What I'm currently having problems is, setting the owner of a folder and then making it so it wont inherit permissions, but will have the ability to replace on lower objects. No inherit so that no matter where you put the folder, the people will always have access to it. Replace Permissions on Child objects because I have a System like this:
User Folder
.....User Documents
.....User Desktop
.....User Scripts
.....User Shared
As well as when I do the Code in my OP, It will add the user, but wont set any permissions. I will probably be working on it about 11 to 12 hours from now. Thanks for all your help.

john Wesley Jul 12th, 2007 11:52 AM

Are you getting any exceptions on execution of the code?

If so what are the details?

Does the user belong to a domain? ie Can the name be passed as "Domain\\MyUser"?

I cant see the problem with my code, once the SetAccessControl method has been called relevantly - though the MSDN documentation yields this:

Directory Security Example

The only difference I can see is that the directory creation and information object instantiation occur as individual statements (ie, the directory already exists, or would have been created earlier), not that it should alter behaviour any.


All times are GMT -5. The time now is 2:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC