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

Jerold Schulman

December 10, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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:

"\jsi001print$" "Everyone" "READ""\jsi001print$" "BUILTINAdministrators" "FULL CONTROL""\jsi001JSI007Bkp" "Everyone" "CHANGE""\jsi001Fax" "Everyone" "READ""\jsi001Fax" "JSIINCDomain Admins" "FULL CONTROL""\jsi001Fax" "BUILTINPrint Operators" "FULL CONTROL""\jsi001Fax" "BUILTINServer 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 offif {%1}=={} @echo Syntax SharePerms ServerName&goto :EOFsetlocalset server=%1set 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)endlocalgoto :EOF:parsesset work=%line:  =#%set /a cnt=0set share=:ploopcall set char=%%work:~%cnt%^,1%%if "%char%" EQU "#" goto getshareif "%char%" EQU ":" goto fixshareset share=%share%%char%set /a cnt=%cnt% + 1if %cnt% LSS 65 goto ploopgoto :EOF:fixshareset /a cnt=%cnt% - 2call set share=%%share:~0,%cnt%%%:getshareset Perm=Nfor /f "Skip=3 Tokens=*" %%p in ('rmtshare \%server%"%share%"') do set line=%%p&call :parsepgoto :EOF:parsepif /i "%line%" EQU "The command completed successfully." goto :EOFif "%Perm%" EQU "Y" goto parsep1if /i "%line%" EQU "Permissions:" set Perm=Ygoto :EOF:parsep1for /f "Tokens=1* Delims=:" %%a in ('@echo %line%') do set who=%%a#&set what=#%%bset who=%who: #=%set who=%who:#=%set what=%what:# =%set what=%what:#=%@echo "\%server%%share%" "%who%" "%what%"



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