JSI Tip 9445. How can I enumerate all the shares on a computer, reporting on share permission and the NTFS permissions of the shared folder tree?
Jerold Schulman
June 12, 2005
1 Min Read
Using RMTShare.exe, which is in the public domain, to enumerate detail share information, like share name, path, remarks, maximum users, current number of connected users, and share permissions, AND CACLS.EXE to enumerate the NTFS permission on the shared folder and its' sub-folders, I have scripted RptSPX.bat.
The syntax for using RptSPX.bat is:
RptSPX ReportFile [Except1 Except2 ... ExceptN]
Where ReportFile is the path to the file that will contain the report, and each ExceptX is a share name that you wish to exclude. RptSPX.bat automatically excludes ADMIN$, IPC$, print$, and $ .
RptSPX.bat contains:
@echo offsetlocal ENABLEDELAYEDEXPANSIONIF {%1}
<h1><a name="_GOTO_bad_set_report_1_if_exist_report_del_q_report_set_except_TEMP_RptSPX__RANDOM_TMP_echo_ADMIN_gt_except_echo_IPC_gt_gt_except_echo_print_gt_gt_except_excl_if_2_" id="_GOTO_bad_set_report_1_if_exist_report_del_q_report_set_except_TEMP_RptSPX__RANDOM_TMP_echo_ADMIN_gt_except_echo_IPC_gt_gt_except_echo_print_gt_gt_except_excl_if_2_">{} GOTO badset report=%1if exist %report% del /q %report%set except="%TEMP%RptSPX_%RANDOM%.TMP"@echo ADMIN$>%except%@echo IPC$>>%except%@echo print$>>%except%:exclif {%2}</a></h1>
{} goto beginset wrk=%2shiftset wrk=%wrk:"=%@echo %wrk%>>%except%goto excl:beginset f1=Findstr /v /b /C:"The command completed successfully."set f2=findstr /v /b /L /i /g:%except%for /f "Skip=4 Tokens=1*" %%a in ('RMTSHARE \%computername%^|%F1%^|%F2%') do ( set shr=%%a if "!shr:~1,2!#" NEQ "$#" call :share)del /q %except%endlocalGOTO :EOF:bad@echo Usage: RptSPX ReportFile [Except1 Except2 ... ExceptN]@echo.endlocal:sharefor /f "Tokens=*" %%r in ('RMTSHARE \%computername%%shr%^|%F1%') do ( @echo %%r>>%report% set line=%%r if "!line:~0,5!" EQU "Path " if "!line:~19,1!" EQU ":" call :folder "!line:~18!" ))@echo .......................................................>>%report%goto :EOF:folderset pf=%1set wrk=%pf:"=%#if "%wrk:~2,2%" EQU "#" set pf=%pf:=%cacls %pf%>>%report%for /f "Tokens=*" %%a in ('dir %pf% /ad /s /b') do ( cacls "%%a">>%report%)
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like