#23630 - 2002-06-20 09:13 PM
script that lists the owner of files
|
Aaron T Granberg
Fresh Scripter
Registered: 2002-04-17
Posts: 15
Loc: MN
|
I was wondering if it is possible to write a KIX script to look at all the files in a directory (WinNT 4.0 TSE SP6) and list who the owners of the files are. This particular folder has over 12000 files in it and I am hoping that KIX could help me to start organizing it. If anyone has any insight into how I could do this with KIX or something else I would GREATLY appreciate it.
Thanks.
|
Top
|
|
|
|
#23631 - 2002-06-20 10:28 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
There is a way.. give me a few and I'll whip up a script (if someone doesn't beat me to it).
Brian
|
Top
|
|
|
|
#23632 - 2002-06-20 10:31 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I can do it through COM... but do you need to know the owner? Or do you need to know who has rights to change the file?
Brian
|
Top
|
|
|
|
#23633 - 2002-06-20 11:24 PM
Re: script that lists the owner of files
|
Aaron T Granberg
Fresh Scripter
Registered: 2002-04-17
Posts: 15
Loc: MN
|
I'd like to know who the owner is so I can tell people what files belong to them so they can clean them up.
I really appreciate your help in this.
|
Top
|
|
|
|
#23634 - 2002-06-20 11:52 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
It's not as straightforward as I thought, but I'm making progress...
Brian
|
Top
|
|
|
|
#23635 - 2002-06-21 02:12 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I've got something that will check the owner of a file.. now i'm reworking it!
Brian
|
Top
|
|
|
|
#23636 - 2002-06-21 03:55 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Okay.. here is my code.. it probably needs to be cleaned up a bit.. and maybe reworked for your needs.. but what it does is create a file that lists the filename with the ownership..
code:
break on
Function GetOwner($fileinput) $wmiobj = GetObject("Winmgmts:") $SIDobj = $wmiobj.ExecQuery("ASSOCIATORS OF {win32_LogicalFileSecuritySetting='$fileinput'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner") For each $SID in $SIDobj $GetOwner=$SID.ReferencedDomainName+"\"+$SID.AccountName Next EndFunction
$fileOutput = "i:\owners.txt" ; place to store the owner list $dir = "m:\" ; directory path. UNC names not supported. Must end in "\"
$ok = RedirectOutput($fileoutput) $filename = DIR($dir) While $filename <> "" AND @error = 0 $file = $dir+$filename $owner = GetOwner($file) ? $file+" "+$owner $filename = DIR() Loop $ok = RedirectOutput("")
If you need it cleaned up to perform tasks based on owner and you need help with that, let me know.
Brian [ 21 June 2002, 17:58: Message edited by: BrianTX ]
|
Top
|
|
|
|
#23637 - 2002-06-21 05:19 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
If anyone else that is good at returning arrays in functions wants to help me create a UDF that returns
GetOwner[0] as username & GetOwner[1] as domain
I'd appreciate the help. I don't know why, but I was fiddling with it earlier and having a lot of problems.
Brian
|
Top
|
|
|
|
#23639 - 2002-06-21 05:57 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
That was kind of what I had in mind.. but what if someone gives an invalid file or folder? Does it still return an array? Or does it break? When I tried it, it broke for some reason.
Brian
|
Top
|
|
|
|
#23640 - 2002-06-21 05:57 PM
Re: script that lists the owner of files
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
See TranslateNAme() also. I use
code:
Function TranslateNAme() ... $TranslateName = $ReturnName, $Error, $ErrorText Endfunction
there and it works fine.
So
$GetOwner = $SID.AccountName, $SID.ReferencedDomainName [ 21 June 2002, 17:58: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#23641 - 2002-06-21 06:07 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I tried all but the first method, guys, and had a problem with the script... (strange).. I'm notoriously bad about including error-correction in my scripts, so anyone want to volunteer to add such to the UDF and post it under the UDF forum? (I know I should do it, myself, but the fun part of figuring out how it works is done, and I don't want to wash the dishes and put them away! lol)
Brian
|
Top
|
|
|
|
#23644 - 2002-06-21 06:23 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
So, do you mean assign 0 to each element in the array? Or just return 0? I would think to be consistent, a function should always return the same type with the same number of elements unless the user can specify a difference when calling the function.
Brian
|
Top
|
|
|
|
#23646 - 2002-06-24 03:03 PM
Re: script that lists the owner of files
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Aaron.. is this what you were looking for? We'd love to find out how things turned out for you.
Brian
|
Top
|
|
|
|
#23647 - 2002-06-24 03:22 PM
Re: script that lists the owner of files
|
Mark Bennett
Getting the hang of it
Registered: 2001-10-10
Posts: 70
|
The Win2k (and NT4) ResKits have some Perl scripts that will do this for you. I have used one in the past to establish owners then 'pruned' the output to a format usable by my script.
|
Top
|
|
|
|
#23648 - 2002-06-24 08:50 PM
Re: script that lists the owner of files
|
Aaron T Granberg
Fresh Scripter
Registered: 2002-04-17
Posts: 15
Loc: MN
|
Thanks a lot you guys. I am totally impressed. I am doing so tests with it and I will let you guys know how it goes.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|