Link to home
Start Free TrialLog in
Avatar of vbtl
vbtlFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get File Owner of a UNC file when run on a Windows 2000 Server

I have the need to be able to retrieve the file owner from a host of files that live throughout our network.  We are provided the UNC names and need to return the file owner.  I can get this working on my workstation, although its very slow, using a mapped drive but not with a unc name.  As a last resort the mapped drive is OK.  The problem is that I need to run this from a server (windows 2000 Server) and that even using a mapped drive, no owner is returned.  

Question is 1) How can I get the file owner from a unc filename, and 2) how can I get it to run on the server?

The code is:

imports system.management

    Public Function GetFileOwner(ByVal strFile As String) As String
        Dim oManagementObject As New ManagementObject("Win32_LogicalFileSecuritySetting.path='" & strFile & "'")
        Dim oManagementBaseObject As ManagementBaseObject
        'oManagementObject.Path = ""
        Dim oDescriptor As ManagementBaseObject
        Dim oOwner As ManagementBaseObject
        Dim Owner As PropertyDataCollection
        Dim strOwner As String
        Try
            'Get the security descriptor for this object
            oManagementBaseObject = oManagementObject.InvokeMethod("GetSecurityDescriptor", Nothing, Nothing)
            oDescriptor = oManagementBaseObject.Properties("Descriptor").Value()
            'Get the Ownerobject
            oOwner = oDescriptor.Properties("Owner").Value
            'Read the Properties to a Propertydatacollection Object
            Owner = oOwner.Properties
            strOwner = Owner("Name").Value
        Catch e As Exception
            MsgBox(e.Message)
            ' Problem getting information
            strOwner = ""
        End Try
        Return (strOwner)
    End Function
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbtl

ASKER

Like it!  Thanks