network file ownership
- How can i use vbscript to display the owner of a file located on a workgroup network share?
I would like to get the result as displayed in File Properties dialog, Details tab, owner property
or shell: cmd /k dir /q "<path>\<filename>"
OS: Windows Vista (32bit) Enterprise, SP1, Office 2007
Thanks,
Frank
All Replies
Per "Windows 2000 Scripting Guide" you can use the Shell.Application object to retrieve extended properties of files, including "Owner". See this link:
http://www.microsoft.com/technet/scriptcenter/guide/sagsas_overview.mspx?mfr=true
However, getting this to work proves to be a pain. First, index numbers seem to vary with OS. The link says "Owner" should be index 8 in the collection of extended file properties, but it is 10 on my Vista computer. Worse, I cannot get any of the extended properties to output unless I loop through all files in the folder, and for each file loop through all extended properties. I don't know why. However, I got the following code to work for one specified file in a specified folder:
=========
Option ExplicitDim objShell, objFolder, strFileName, strFolder, strFile, k
Dim arrHeaders()' Specify the folder.
strFolder = "c:\Scripts"' Specify the file in the folder.
strFileName = "EnumAdm.vbs"Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strFolder)' Retrieve names of extended file properties.
For k = 0 To 100
ReDim Preserve arrHeaders(k)
arrHeaders(k) = objFolder.GetDetailsOf(objFolder.Items, k)
Next' Enumerate all files in the folder.
For Each strFile In objFolder.Items
' Only consider the specified file.
If (strFile = strFileName) Then
' Enumerate extended file properties.
For k = 0 To 100
' Only display "Owner" of specified file.
If (arrHeaders(k) = "Owner") Then
Wscript.Echo strFile & ", " & arrHeaders(k) & ": " & objFolder.GetDetailsOf(strFile, k)
End If
Next
End If
Next
==========
I assume this will also work if you use a UNC path, but you must specify the folder and file separately. Notice that I first retrieve the names of all extended file properties, then loop through all files in the folder, but only consider the specified file. Then I loop through all extended properties, but only output when the name of the property is "Owner". Thus, the code doesn't care which index (value of k) corresponds to owner.
Also, the link indicates that there are only 35 extended properties, but I find many more. I limited the enumeration to 101, so I'm assuming that "Owner" is among the first 101. I hope this helps.
Richard Mueller
MVP ADSI

