Using RMTShare.exe, I have scripted EnumShares.bat to enumerate the shares on the local
or on a remote computer.
The syntax for using EnumShares.bat is best described with the following snippet:
@echo off setlocal for /f "Tokens=1-6*" %%a in ('call EnumShares %1') do ( call :process %%a %%b %%c %%d %%e %%f %%g ) endlocal goto :EOF :process set shr=%1&set rsc=%2&set rmk=%3&set max=%4&set /a nu=%5&set /a np=%6 @echo %shr% %rsc% %rmk% %max% %nu% %np% if "%np%" NEQ "0" call :xps %* @echo. goto :EOF :xps if \{%7\}EnumShares.bat contains:\{\} goto :EOF set user=%7&set perm=%8 @echo %user% %perm% shift&shift goto xps which might produce an output that contains: "NETLOGON" "C:\WINDOWS\sysvol\sysvol\JSIINC.COM\SCRIPTS" "Logon server share" "No limit" 1 2 "Everyone" "READ" "BUILTIN\Administrators" "FULL CONTROL" "HP2250" "HP Business Inkjet 2250 (PCL5C),LocalsplOnly" "Fastest" "No limit" 0 4 "BUILTIN\Administrators" "FULL CONTROL" "JSIINC\Domain Users" "FULL CONTROL" "Everyone" "FULL CONTROL" "BUILTIN\Print Operators" "FULL CONTROL" Where: %1 is an optional NetBIOS remote computer name. In the Process sub-routine: %1 is a quoted share name, like "NETLOGON" or "ADMIN$". %2 is a quoted resource, like "C:\WINDOWS\sysvol\sysvol\JSIINC.COM\SCRIPTS". %3 is a quoted remark, like "Logon server share" or "". %4 is a quoted maximum number of users, like "No Limit" or "3". %5 is the number of users currently connected to the share, like 0 or 7. %6 is the number of permissions set on the share, like 0 or 3. %7 is a table of %6 permission sets, UserName and permission pairs. If %6 is 0, the table is empty. If %6 is 2, the table might contain: "Everyone" "READ" "BUILTIN\Administrators" "FULL CONTROL"
@echo off setlocal ENABLEDELAYEDEXPANSION set fnd="The command completed successfully." set comp=\\%ComputerName% if not \{%1\}\{\} set comp=\\%1 for /f "Skip=4 Tokens=1*" %%a in ('rmtshare %comp%^|Findstr /V /C:%fnd%') do ( set shr=%%a call :detail @echo "!shr!" "!rsc!" "!rmk!" "!mxu!" !nu! !prmc! !prmt! ) endlocal goto :EOF :detail set perm=N set /a prmc=0 set prmt=# for /f "Skip=1 Tokens=*" %%b in ('rmtshare %comp%\"%shr%"^|Findstr /V /C:%fnd%') do ( set line=%%b if "!perm!" EQU "Y" call :detailp if "!perm!" NEQ "Y" if "!line:~0,12!" EQU "Permissions:" set perm=Y if "!perm!" NEQ "Y" call :detaill ) set prmt=!prmt:~1! set rsc=!rsc: =! set rsc=!rsc: ##=! set rsc=!rsc:##=! set rmk=!rmk: =! set rmk=!rmk: ##=! set rmk=!rmk:##=! goto :EOF :detaill set c2=!line:~18! if "!line:~0,4!" EQU "Path" set rsc=!c2!##&goto :EOF if "!line:~0,6!" EQU "Remark" set rmk=!c2!##&goto :EOF if "!line:~0,13!" EQU "Maximum users" set mxu=!c2!&goto :EOF if "!line:~0,5!" EQU "Users" set /a nu=!c2!&goto :EOF ) goto :EOF :detailp set /a prmc=%prmc% + 1 for /f "Tokens=1* Delims=:" %%c in ('@echo %line%') do ( set p1=%%c# set p2=%%d set p1=!p1: #=! set p1="!p1:#=!" set p2="!p2:~1!" if !p1! EQU "\Everyone" set p1="Everyone" set prmt=!prmt! !p1! !p2! )
0 comments
Hide comments