Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetOwner NTFS Permissions

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
GB
Hi all,

I have this code:

Code:
    Private Sub setOwner(ByRef FileName As String, ByRef account As NTAccount)
        Try
            Dim dInfo As New DirectoryInfo(FileName)
            Dim dir As New DirectorySecurity(FileName, AccessControlSections.None)

            dir.SetOwner(account)
            dInfo.SetAccessControl(dir)

            dir = Nothing
            dInfo = Nothing
            If System.IO.Directory.Exists(FileName) Then
                Dim Files As String()
                Files = Directory.GetFileSystemEntries(FileName)

                For Each element As String In Files
                    setOwner(element, account)
                Next
            End If

        Catch er As Exception
            Writetolog(FileName, "ERROR", "Catch 1 Set owner - " + er.Message)
        End Try

    End Sub

Which works perfectly (the account used is a domain admin) - unless......

The administrator account has had its permissions removed from the folder.

If i am using the windows front end - i can claim ownership of the folder and then set permissions. However the above will not claim ownership for me. Instead it errors.

er.Message = "Method failed with unexpected error code 87."

Any ideas how i can claim ownership of a folder that i have no permissions (yet because i am admin i can claim permissions.

Dan



----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top