WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Version and Dir Mgmt

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Directory Permissions Reporter


Directory Permissions Reporter This will walk through a directory and sub-directories (configurable depth) and return the permissions assigned in a HTML report. Opens IE at the end to display the report.

I tossed it together to do quick some reporting / cleanup. If you decide to use it you may want to validate that I'm pulling and translating the permissions properly.

I haven't really tested it in depth yet.

AddExtender("WWWNT34I.DLL") 
;This UDF is sort of like the DirItemize function in that it returns a
;tab delimited list of directories.  

; This function returns a tab delimited list of directories in a directory tree.
; Parameters
;       tree - always initialize to ""
;       dir  - directroy to start in
;       mask - file mask to search for, almost ALWAYS "*.*"   !!!!!!!!!!!!!!!
;              no directory info allow in the mask
;       currentlevel - initialize to zero
;       maxlevel  - controls how many levels deep you wish to go.  TO
;                   go all the way down set to a large number like 9999
;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineFunction DirItemRecursive(tree,dir,mask,currentlevel,maxlevel)
   ;DebugTrace(@ON,"xxxdebug.txt")
   If currentlevel>=maxlevel Then Return(tree)
   currentlevel=currentlevel+1

   DirChange(dir)

   If tree=="" Then tree=DirGet()
   Else tree=StrCat(tree,@TAB,DirGet())
   dlist=ItemSort(DirItemize("*.*"),@TAB)
   dcount=ItemCount(dlist,@TAB)

   For xx=1 To dcount
      thisdir=ItemExtract(xx,dlist,@TAB)
      tree=DirItemRecursive(tree,thisdir,mask,currentlevel,maxlevel)
   Next

   DirChange("..")
   Return(tree)
#EndFunction

;-------------------------------------------------------------------------
#DefineFunction GetAccess(dir)
	records=""
	userlist = wntAccessList("",dir , 300, 1)
	usercount = ItemCount(userlist,@TAB)
	For x=1 to usercount
		user=ItemExtract(x,userlist,@TAB)
		permissions=wntAccessGet("",dir,user,300,0)

		;Make Human Readable
		permissions=StrReplace(permissions,"1:9:268435456|1:2:2032127","(No Access)")
		Permission1=ItemExtract(1,permissions,"|")
		Permission2=ItemExtract(2,permissions,"|")
		Assigned1=ItemExtract(-1,permission1,":")
		Assigned2=ItemExtract(-1,permission2,":")
		permissions=strcat(Assigned1,Assigned2)
		permissions=StrReplace(permissions,"2032127","(Full Control)")
		permissions=StrReplace(permissions,"268435456","(Full Control)")
		permissions=StrReplace(permissions,"1245631","(Change)")
		permissions=StrReplace(permissions,"-536805376","(Change)")
		permissions=StrReplace(permissions,"1180095","(Add & Read)")
		permissions=StrReplace(permissions,"-1610612736","(Add & Read)")
		permissions=StrReplace(permissions,"-1610612736","(Read)")
		permissions=StrReplace(permissions,"1179817","(Read)")		
		permissions=StrReplace(permissions,"1180086","(Add)")
		permissions=StrReplace(permissions,"1179817","(List)")

		If records==""
			records=StrCat(user," ",permissions)
		Else
			records=StrCat(records,@TAB,user," ",permissions)
		EndIf
	Next
	
	Return(records)
#EndFunction
;-------------------------------------------------------------------------

;Global Garbage...
Dir="C:\Winnt"
DefaultDepth=ItemCount(Dir,"\")+1
List=""
WBFile=IntControl(1004,0,0,0,0)
WBCount=ItemCount(WBFile,"\")
WBDir=ItemRemove(WBCount,WBFile,"\")
curlevel=0
mask="*.*"

:Dlg
WalkerFormat=`WWWDLGED,6.1`
WalkerCaption=`Permissions Walker`
WalkerX=1000
WalkerY=1000
WalkerWidth=166
WalkerHeight=098
WalkerNumControls=007
WalkerProcedure=`DEFAULT`
WalkerFont=`DEFAULT`
WalkerTextColor=`DEFAULT`
WalkerBackground=`DEFAULT,DEFAULT`

Walker001=`043,075,036,012,PUSHBUTTON,DEFAULT,"OK",1,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker002=`091,075,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker003=`041,019,088,012,EDITBOX,startdir,DEFAULT,DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker004=`131,019,016,012,PUSHBUTTON,DEFAULT,"...",2,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker005=`011,021,028,012,STATICTEXT,DEFAULT,"Start Path",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker006=`013,041,078,010,STATICTEXT,DEFAULT,"Sub-Directory Depth to Process",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Walker007=`093,039,024,012,SPINNER,maxlevel,"1",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("Walker")

If ButtonPushed==0 Then Exit

If ButtonPushed==2
	startdir=AskDirectory("","","C:\","",0)
   Goto Dlg
EndIf

If startdir==""
	Message("Error","Please enter a valid start directory")
	Goto Dlg
EndIf


List=DirItemRecursive("",startdir,mask,curlevel,maxlevel)

;Write HTML Header
If !DirExist("C:\temp") Then DirMake("C:\Temp")
If !FileExist("C:\temp\folder.gif") Then FileCopy("%WBDir%\folder.gif","C:\temp\folder.gif",@FALSE)


output=FileOpen("C:\Temp\Permissions_Output.html","WRITE")
FileWrite(output,"<HTML>")
FileWrite(output,"<BR><BR>")
FileWrite(output,'<FONT FACE="Verdana">')
FileWrite(output,'<TABLE Border="1" ALIGN="Center">')
FileWrite(output,'<TR><TD Align="Center"><B>Directory</B></TD><TD Align="CENTER"><B>Permissions</TD></B></TR>')

;Start Checking Permissions

ListCount=ItemCount(List,@TAB)
For x=1 to ListCount
	Dir=ItemExtract(x,List,@TAB)

	If Dir!="" 
		Rights=GetAccess(Dir)
		Depth=ItemCount(Dir,"\")-DefaultDepth
		Dir=StrCat('<IMG SRC="folder.gif"> ',Dir)
		For z=1 to Depth
			Dir=StrCat('      ',Dir)
		Next
		HTMLDirData=Strcat('<TR><TD ALIGN="TOP"><FONT SIZE="-1">',Dir,'</TD>')
		FileWrite(output,HTMLDirData)
		FileWrite(output,'<TD><Font Size="1">')
		Count=ItemCount(Rights,@TAB)
		For y = 1 to Count
			AccessList=ItemExtract(y,Rights,@TAB)
			FileWrite(output,'%AccessList%<BR>')	
		Next
		FileWrite(output,"</TD></TR>")
	EndIf
Next

:CloseHTML
FileWrite(output,'</TABLE>')
FileWrite(output,"</F0NT>")
FileWrite(output,"</HTML>")
FileClose(output)

Run("Iexplore.exe","C:\Temp\Permissions_Output.html")

Article ID:   W16215
File Created: 2004:03:30:15:43:16
Last Updated: 2004:03:30:15:43:16