Ok, so I'm using VBScript. I'm trying to print out the owner of a file or folder. However it seems to be failing when scanning through the files/folders if it comes to a shortcut or other similar items? And, it was mentioned you need to check for nulls and empties before executing. So, when it fails it occurs at the "For Each" line. Is anyone familiar with this? I'd really like to get this to work, but am having trouble getting around this issue and finding more info on it.
Code:
Sub FindFileOwner2(strFile)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _
& " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem in colItems
objTextFile.Write(objItem.AccountName & vbTab & strFile & vbCrLf)
Next
End Sub