locked
Can I set a hard disk's permission to Full Control?

    Question

  • Hello

    My hard disk "D:" is shared on local network and set to Read only.

    Can I set it to Full Control by using VB.NET code?

    Is there code to do that?

     

    Thanks

    Saturday, June 02, 2007 3:17 AM

Answers

  • I just had a feeling that there must be an easier way ....

     

    Code Snippet

    Dim folder_info As New DirectoryInfo("C:\")

    Dim foldersecurity As DirectorySecurity = folder_info.GetAccessControl(AccessControlSections.Access)

    Dim MyRule As New System.Security.AccessControl.FileSystemAccessRule("DOMAIN\USER", FileSystemRights.FullControl, AccessControlType.Allow)

    foldersecurity.AddAccessRule(MyRule)

    folder_info.SetAccessControl(foldersecurity)

     

    Obviously this code works when run on the pc that is sharing.  You must have permission to make the change also.

    Saturday, June 02, 2007 2:46 PM
  • Just to confirm:

    ACLs are sometimes reffered to as NTFS permissions...because you can only use them on NTFS drives. You cant change permissions on FAT32 drives, like you said ACLs are for NTFS drives only.

     

    Have you actually edited the code that was provided to change the "DOMAIN\USER" to your PC name and your username and change C:\ to D:\?

     

    I also tried running the code you provided under a button click event, nothing happens though. No error but the directory I entered did not get its ACL changed.

    Monday, June 04, 2007 12:48 PM

All replies

  • I don't think there is a one liner for this !  I'm assuming it's an NTFS drive not FAT.

     

    This is the best way I know:

    http://www.codeproject.com/useritems/WIN32_Share.asp

     

    It's in Csharp but easy to translate, just quite a lot of code!!  Perhaps some one has done this already, if not I'll translate Smile

     

     

    Saturday, June 02, 2007 2:05 PM
  • I just had a feeling that there must be an easier way ....

     

    Code Snippet

    Dim folder_info As New DirectoryInfo("C:\")

    Dim foldersecurity As DirectorySecurity = folder_info.GetAccessControl(AccessControlSections.Access)

    Dim MyRule As New System.Security.AccessControl.FileSystemAccessRule("DOMAIN\USER", FileSystemRights.FullControl, AccessControlType.Allow)

    foldersecurity.AddAccessRule(MyRule)

    folder_info.SetAccessControl(foldersecurity)

     

    Obviously this code works when run on the pc that is sharing.  You must have permission to make the change also.

    Saturday, June 02, 2007 2:46 PM
  • I faced problems in VB2005.

    It says these types are invalid

    DirectorySecurity - FileSystemRights - AccessControlType

     

    And does it work on FAT32 hard disks?

    Saturday, June 02, 2007 3:39 PM
  • You need 

    Code Snippet

    Imports System.Security.AccessControl

    Imports System.IO

     

    Sorry I forgot to mention them.

     

    Not sure if they will work on FAT since ACLs for NTFS.  I'll chk and see.

    Saturday, June 02, 2007 9:05 PM
  • I run the project and nothing happened, nothing changed.

     

    P.S. My computer isn't a domain and I use Windows XP Pro SP2.

    Sunday, June 03, 2007 12:28 AM
  • Even if your computer is not in a domain you can use the name of your PC instead.  Did you get an error?
    Monday, June 04, 2007 6:37 AM
  • Just to confirm:

    ACLs are sometimes reffered to as NTFS permissions...because you can only use them on NTFS drives. You cant change permissions on FAT32 drives, like you said ACLs are for NTFS drives only.

     

    Have you actually edited the code that was provided to change the "DOMAIN\USER" to your PC name and your username and change C:\ to D:\?

     

    I also tried running the code you provided under a button click event, nothing happens though. No error but the directory I entered did not get its ACL changed.

    Monday, June 04, 2007 12:48 PM
  • I got nohting and nothing happen.

    My computer name is ONH1986 and username is MyName.

    I put this code:

    Dim MyRule As New System.Security.AccessControl.FileSystemAccessRule("ONH1986\MyName", FileSystemRights.FullControl, AccessControlType.Allow)

     

    And my hard is NTFS.

     

    Monday, June 04, 2007 4:58 PM
  • What's wrong?
    Tuesday, June 05, 2007 3:24 AM