Page 1 of 1 1
Topic Options
#23630 - 2002-06-20 09:13 PM script that lists the owner of files
Aaron T Granberg Offline
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 Offline
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 Offline
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 Offline
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 Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
It's not as straightforward as I thought, but I'm making progress... [Smile]

Brian

Top
#23635 - 2002-06-21 02:12 PM Re: script that lists the owner of files
BrianTX Offline
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! [Smile]

Brian

Top
#23636 - 2002-06-21 03:55 PM Re: script that lists the owner of files
BrianTX Offline
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 Offline
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
#23638 - 2002-06-21 05:45 PM Re: script that lists the owner of files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Would this be where your driving with this, Brian ?

break on

Function GetOwner($fileinput)
 dim $a[1]
 $GetOwner=0
 $wmiobj = GetObject("Winmgmts:")
 $SIDobj = $wmiobj.ExecQuery("ASSOCIATORS OF {win32_LogicalFileSecuritySetting='$fileinput'}
                               WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
  For each $SID in $SIDobj
   $a[0] = $SID.AccountName
   $a[1] = $SID.ReferencedDomainName
   $GetOwner=$a
  Next
EndFunction

$file = "c:\temp"
$array = GetOwner($file)
?"AccountName=" $array[0]
?"DomainName=" $array[1]



-Shawn

{EDIT}

Guess you could do this as well:

Function GetOwner($fileinput)
 redim $GetOwner[1]

 ...

 For each $SID in $SIDobj
  $GetOwner[0] = $SID.AccountName
  $GetOwner[1] = $SID.ReferencedDomainName
 Next



--Shawn

[ 21 June 2002, 17:48: Message edited by: Shawn ]

Top
#23639 - 2002-06-21 05:57 PM Re: script that lists the owner of files
BrianTX Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#23641 - 2002-06-21 06:07 PM Re: script that lists the owner of files
BrianTX Offline
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
#23642 - 2002-06-21 06:08 PM Re: script that lists the owner of files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I would rig it so that the funtion set @ERROR, and if it was successfull, the user can assume the function returned an array, and if it not, just have the function return a 0 (zero).
Top
#23643 - 2002-06-21 06:15 PM Re: script that lists the owner of files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
You might wonder why you would want to return a 0 (zero). Because that would stop a user that used you UDF in a for-each-in-next statement, from actually running the loop. If you return a 0, the for loop never executes, and the script just carries on - ie, no data !
Top
#23644 - 2002-06-21 06:23 PM Re: script that lists the owner of files
BrianTX Offline
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
#23645 - 2002-06-21 06:27 PM Re: script that lists the owner of files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, this could proably turn into quite a debate, but I figured you could (if you wanted), only return a valid array, or nothing (zero). In this case, the user probably would NOT iterate over your array using for-each-in-next anyways. Its up to you Brian ... the most important thjing is to do whatever makes sense to you !

[ 21 June 2002, 18:28: Message edited by: Shawn ]

Top
#23646 - 2002-06-24 03:03 PM Re: script that lists the owner of files
BrianTX Offline
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 Offline
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 Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 35 anonymous users online.
Newest Members
thequeen, ameliaryan, shalomsalami, dkdssdk, Vroon
17639 Registered Users

Generated in 0.039 seconds in which 0.01 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org