# Solved: vbScript File Owner



## draceplace (Jun 8, 2001)

How do I get the file owner in a vbscript? In DOS you see the file owner with "dir /Q " . I can't find the VB equivant!!

Wow!, can't believe this question is that hard...I'm looking for a "objFile.Size" like property "objFile.Owner" except that's not it. I've Googled and looked but I'm missing it somehow. surely someone here knows this!!

Thanks for reading my post!!


----------



## draceplace (Jun 8, 2001)

Public strFileOwner

Sub GetFileOwner(strFile)
Set colItems = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _
& " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem in colItems
' Wscript.Echo objFile.Name & " " & objItem.AccountName
strFileOwner = objItem.AccountName
Next 
End Sub


----------



## draceplace (Jun 8, 2001)

Found out you should check for nulls and empties before you execute. Short cuts and other junk in a directory will cause it to fail....Also so another that seems it would work:

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\aScripts\origionals")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrHeaders(13)
For i = 0 to 13
arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
For i = 0 to 13
If i <> 9 then
Wscript.echo arrHeaders(i) _
& ": " & objFolder.GetDetailsOf (strFileName, i) 
End If
Next
Wscript.Echo
Next


----------

