vbtl
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_Lo gicalFileS ecuritySet ting.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.InvokeMe thod("GetS ecurityDes criptor", Nothing, Nothing)
oDescriptor = oManagementBaseObject.Prop erties("De scriptor") .Value()
'Get the Ownerobject
oOwner = oDescriptor.Properties("Ow ner").Valu e
'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
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_Lo
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.InvokeMe
oDescriptor = oManagementBaseObject.Prop
'Get the Ownerobject
oOwner = oDescriptor.Properties("Ow
'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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER