JSI Tip 7554. How do I list the shares and share permissions on a 'server'?

Using RMTShare.exe, I have scripted SharePerms.bat to list the shares and permission on a 'server'.

The syntax for using SharePerms.bat is:

SharePerms ServerName

Where ServerName is the computer name of any computer that hosts one or more shares.

The ouptut is displayed in the CMD window and will look similar to:

"\\jsi001\print$" "\Everyone" "READ"
"\\jsi001\print$" "BUILTIN\Administrators" "FULL CONTROL"
"\\jsi001\JSI007Bkp" "\Everyone" "CHANGE"
"\\jsi001\Fax" "\Everyone" "READ"
"\\jsi001\Fax" "JSIINC\Domain Admins" "FULL CONTROL"
"\\jsi001\Fax" "BUILTIN\Print Operators" "FULL CONTROL"
"\\jsi001\Fax" "BUILTIN\Server Operators" "FULL CONTROL"
You can pipe the output to a file using the following syntax:

SharePerms ServerName >FileName

You can use the output in subsequent commands, as in:

for /f "Tokens=*" %%i in ('SharePerms ServerName') do SomeCommand %%i

SharePerms.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax SharePerms ServerName&goto :EOF
set server=%1
set server=%server:\=%
for /f "Skip=4 Tokens=*" %%s in ('rmtshare \\%server%') do (
 if /i "%%s" NEQ "The command completed successfully." set line=%%s&call :parses
goto :EOF
set work=%line:  =#%
set /a cnt=0
set share=
call set char=%%work:~%cnt%^,1%%
if "%char%" EQU "#" goto getshare
if "%char%" EQU ":" goto fixshare
set share=%share%%char%
set /a cnt=%cnt% + 1
if %cnt% LSS 65 goto ploop
goto :EOF
set /a cnt=%cnt% - 2
call set share=%%share:~0,%cnt%%%
set Perm=N
for /f "Skip=3 Tokens=*" %%p in ('rmtshare \\%server%\"%share%"') do set line=%%p&call :parsep
goto :EOF
if /i "%line%" EQU "The command completed successfully." goto :EOF
if "%Perm%" EQU "Y" goto parsep1
if /i "%line%" EQU "Permissions:" set Perm=Y
goto :EOF
for /f "Tokens=1* Delims=:" %%a in ('@echo %line%') do set who=%%a#&set what=#%%b
set who=%who: #=%
set who=%who:#=%
set what=%what:# =%
set what=%what:#=%
@echo "\\%server%\%share%" "%who%" "%what%"

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.