DougInCanada
Technical User
does anyone know of WMI object.Item or API call to find the owner info of any documents/folders in a given folder using the 'Owner' attribute, much like the details view in Windows?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
'On Error Resume Next
Dim refWMI
Dim strQuery
Dim colOwner
Dim refItem
Dim FSO
Dim txtFileOwner
Dim txtFileName
Dim FileSpec
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists ("C:\FileOwner.txt") then
FSO.DeleteFile "C:\FileOwner.txt"
End If
Set txtFileOwner = FSO.CreateTextFile ("C:\FileOwner.txt")
txtFileOwner.close
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set txtFileName = FSO.openTextFile("C:\FileNames.txt", ForReading)
Set txtFileOwner = FSO.openTextFile("C:\FileOwner.txt", ForAppending)
Do Until txtFileName.atendofstream=true
set refWMI = GetObject("winMgmts:\\")
filespec=txtFileName.readline
strQuery = "ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=" & _
"'" & filespec & "'} WHERE " & _
"AssocClass=Win32_LogicalFileOwner " & _
"ResultRole=Owner"
set colOwner = refWMI.ExecQuery(strQuery)
For Each refItem In colOwner
If Err = 0 Then
txtFileOwner.writeline filespec & " is owned by " & refItem.AccountName
End If
Next
Set colOwner = Nothing
set refWMI = Nothing
loop