Home All Groups Group Topic Archive Search About

Getting File Owner with .NET 2

Author
14 Mar 2006 9:29 PM
John G
I have the following VB.NET code (VS2005) to get the owner of a file.  It
works fine on my PC but I get exception errors when accessing mapped drives. 
Documentation on the new classes is non-existant.  strFile is a full path and
filename.

       Private Function GetFileOwner(ByVal strFile As String) As String
        Dim FS As FileSecurity = File.GetAccessControl(strFile)
        Dim owner As Security.Principal.NTAccount =
CType(FS.GetOwner(GetType(Security.Principal.NTAccount)),
Security.Principal.NTAccount)

        Return owner.ToString  End Function

Any help would be appreciated.
--
John G

AddThis Social Bookmark Button