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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File ownership problems

Status
Not open for further replies.

tomed

Programmer
Apr 1, 2002
64
US
Are there any utilities out there that would allow me to view ownership or security data on files a directory at a time? I'm having trouble with people losing ownership of files and then (of course) they can't access them until I take ownership and reset the security.

A utility like I described would be a great help to finding and eliminating this problem.
 
I have had issues where my users have incorrect security settings in some of their profiles, I wrote this little script that provides me a list of files that have the Everyone Group in the discretionary access control list which notifies me of a problem. Also, I use a utility called subinacl.exe from the resource kit to correct file ownership problems.

'Force script to run in csript
RunWithCscript

'This script pulls non local security permissions from a specified path.

Set WShshell = CreateObject("Wscript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
'Specify where you want the output to be located.
FilePath=WShshell.specialfolders("Desktop")&"\Security Information.txt"

'Set the messages for the folder question
InitialMsg="Please enter the name of the folder to check." _
&vbCr &vbCr &"i.e. \\servername\homedirs\userdir"
SecondMsg="Sorry you must enter a path." &vbCr &"Or press Cancel to quit." &vbCr

'Get the path info
FolderPath=getinfo (Initialmsg)
ProcessFolder(FolderPath)

Sub ProcessFolder(FolderPath)
Set folder = fs.getfolder(FolderPath)
Wscript.echo FolderPath
ShowPermissions(Folder)
For Each File In Folder.files
If InStr(File,"\Local Settings\")=0 Then ShowPermissions(File)
Next
For Each subfolder In folder.subfolders
ProcessFolder(Subfolder)
Next
End Sub

Sub ShowPermissions(Path)
Dim ADSSEcurity
Dim sec
Set sec = CreateObject("ADsSecurity")
Dim sd
Dim dacl
Dim ace
'On Error Resume Next
Set sd = sec.GetSecurityDescriptor("FILE://" & Path)
'"sd.Control = " & sd.Control
'"sd.DaclDefaulted = " & sd.DaclDefaulted
'"sd.Group = " & sd.Group
'"sd.Owner = " & sd.Owner
'"sd.Revision = " & sd.Revision
'"sd.SystemAcl = " & sd.SystemAcl

Set dacl = sd.DiscretionaryAcl


'writefile FilePath,"sd.Owner = " & sd.Owner
'-- Show the ACEs in the DACL ----
For Each ace In dacl
If InStr(ace.Trustee,&quot;Everyone&quot;)<>0 Then
wscript.echo &quot;Problem Found with &quot; &Path
wscript.echo &quot;Writing information to &quot; &FilePath
writefile FilePath,&quot;Path = &quot; & Path
End If
Next
End Sub

Function WriteFile(Filename,Text)
Const ForReading = 1, ForWriting = 2, ForAppending=8
Dim fs, f
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fs.OpenTextFile(FileName, ForAppending, True)
f.WriteLine Text
F.Close
End Function


Function GetInfo(ask)
GetInfo= InputBOx(ask,&quot;Please enter the requested information&quot;)
If GetInfo = vbEmpty Then WScript.Quit
If GetInfo = &quot;&quot; Then getInfo SecondMSg &initialmsg
End Function

'This subroutine calls this script with cscript.exe then closes wscript
Sub RunWithCscript
If Lcase(Mid(Wscript.Fullname, InstrRev(Wscript.fullname,&quot;\&quot;)+1))=&quot;cscript.exe&quot; Then
'nothing
else
Set WshShell=CreateObject(&quot;Wscript.Shell&quot;)
WshShell.run &quot;Cscript.exe &quot;&quot;&quot; & Wscript.ScriptFullName & &quot;&quot;&quot;&quot;
WScript.Quit 'Quit Wscript
end if

end sub
 
Thanks Guy! I'll give that a try.

I also stumbled on something in Crystal Reports that lets me connect to a directory as a data source and report on all kinds of file attribs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top