Having problems with the following script. When the variable fName is a path such as, c:\Folder\subFolder, p:\folder\subfolder, the script works. When the variable fName is a path such as \\domainFileServer\folder\Subfolder, I get an automation error. Any suggestions
Code:
Function getOwner(fName)
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & fName & "'}" _
& " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem In colItems
getOwner = getDisplayName(objItem.AccountName)
Next
End Function
Public Function getDisplayName(ByVal vSAN)
Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=User)(samAccountName=" & vSAN & "));DisplayName;subtree"
Set oRecordSet = oCommand.Execute
getDisplayName = oRecordSet.Fields("DisplayName")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function