Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document owner information 1

Status
Not open for further replies.

DougInCanada

Technical User
Feb 1, 2004
98
0
0
CA
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?
 
Further notes (for the alternative script):

This is concerned with your latter version. The main correction you have to make is the binding moniker.

[tt]Set refSetting = getobject("winmgmts:\\"& SERVER &"\root\cimv2[red]:[/red]Win32_LogicalFileSecuritySetting='" & filespec & "'")[/tt]

Else, the points considered for the other script are equally applicable.

- tsuji
 
Hi again, Tsuji.

Thank you for being patient with me. Sorry for the mix-up of scripts. The second one seemed shorter and therefore I assumed it would be easier to troubleshoot. My mistake.

Back to the original script:
Code:
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

An error message occurs on this line:

[red]For Each refItem In colOwner[/red]

and the message is simply:
[blue]error: 0x80041002
code: 80041002
source: (null)[/blue]

Again, sorry for the mix-up and any help would be greatly appreciated. It's so close...
 
DougInCanada,

[1] One thing I'm never be sure what is the read out of your filespec. Does it look correct? Does it in the form of urn with servername there? Do not let the issue turn the full circle where you start!
[2] When you prepare the text file, it is easily to leave empty line slipped in. So if filespec="" be sure you do not let it pass on for processing.

In any case, put an echo after the filespec during this stage of development for visual inspection.
[tt] filespec=txtFileName.readline
wscript.echo filespec 'comment it out later
if not isempty(trim(filespec)) then
'your processing instruction developed
'else do nothing and proceed with the following read
end if
[/tt]
[3] Where is the role of server (remote machine) now, it just disappears! You said it works for you local m/c.

If it is on a fat32, it won't return a colOwner. But, can you answer [1] - [3] first fix the givens?

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top