none
Determine if a user has write rights to a directory RRS feed

  • Question

  • I need to see if users have write rights to a specific network directory mapped to a known drive letter and abort code if they don't have rights to write. What I've tried below isn't working. Any tips or pointers would be appreciated.

    Thanks in advance.

    Doug 

    I started from this link:

    http://www.devguru.com/technologies/vbscript/14077

    And built this. For directories on my local PC, I always get '16'. For anything on a server, I get '48' no matter what rights I have for the directory.

    Sub DirRights()
    '    
        Dim objFSO As Variant
        Dim objFolder As Variant
        Dim path As String
       
        path = "Drive:\Path\"
       
       
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFolder = objFSO.GetFolder(path)
       
        MsgBox "Attributes for: " & path & "is: " & objFolder.Attributes
       
        'If objFolder.Attributes And ReadOnlyDir Then
         '   MsgBox "Read Only Directory"
        'Else
         '   MsgBox "Not a read only directory"
        'End If
    '
    End Sub

    Wednesday, December 3, 2014 5:55 PM

Answers

  • You could attempt to write a zero length text file, which you could do with your FSO or Open/Print/Close. If it fails you don't have write rights (assuming the folder exists & the network is good), if it succeeds delete the file with FSO or KILL
    • Marked as answer by 42Doug Wednesday, December 3, 2014 7:23 PM
    Wednesday, December 3, 2014 7:18 PM
    Moderator

All replies

  • You could attempt to write a zero length text file, which you could do with your FSO or Open/Print/Close. If it fails you don't have write rights (assuming the folder exists & the network is good), if it succeeds delete the file with FSO or KILL
    • Marked as answer by 42Doug Wednesday, December 3, 2014 7:23 PM
    Wednesday, December 3, 2014 7:18 PM
    Moderator
  • Darn, I was hoping I could just get some attribute and call it a day... Thank you.
    Wednesday, December 3, 2014 7:23 PM
  • There might be an attribute approach and you can certainly use a series APIs, but I think what I suggested is both simple and reliable!
    Wednesday, December 3, 2014 7:31 PM
    Moderator
  • Simple + Reliable = best answer!

    Wednesday, December 3, 2014 7:48 PM