|
|
|||||||
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. |
||||||||
|
|
|||||||
There is a way.. give me a few and I'll whip up a script (if someone doesn't beat me to it). Brian |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
It's not as straightforward as I thought, but I'm making progress... Brian |
||||||||
|
|
|||||||
I've got something that will check the owner of a file.. now i'm reworking it! Brian |
||||||||
|
|
|||||||
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:If you need it cleaned up to perform tasks based on owner and you need help with that, let me know.break on Brian [ 21 June 2002, 17:58: Message edited by: BrianTX ] |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 ] |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
See TranslateNAme() also. I use code:there and it works fine.Function TranslateNAme() So $GetOwner = $SID.AccountName, $SID.ReferencedDomainName [ 21 June 2002, 17:58: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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). |
||||||||
|
|
|||||||
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 ! |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 ] |
||||||||
|
|
|||||||
Aaron.. is this what you were looking for? We'd love to find out how things turned out for you. Brian |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |