JSI Tip 8486. What users are currently connected to my share?

I have scripted ShareUse.bat to determine the number of users connected to a specified locally hosted share, and to return those user names.

Shareuse.bat uses RMTShare.exe, which is in the public domain, to return the number of users connected, and the built in net share command to return the connected user names.

The syntax for using ShareUse.bat is:

ShareUse ShareName

where ShareName can be a file or printer share, and cannot contain any spaces.

The output is displayed on the CMD console, but you can process it in your script using:

for /f "Tokens=1*" %%a in ('ShareUse ShareName') do (
 call :YourLabel %%a %%b
goto ...
set /a number=100000%1%%100000
if \{%2\}

\{\} goto finish set user=%2 shift ... ... goto loop

ShareUse.bat contains:
@echo off
if \{1\}\{\} @echo Syntax: ShareUse ShareName&goto :EOF
set sn=%1
set sn=%sn:"=%
if not exist \\%ComputerName%\%sn% @echo 0&endlocal&goto :EOF
for /f "Tokens=1,2" %%a in ('rmtshare \\%ComputerName%\%sn%^|Find "Users   "') Do (
 set /a nu=100000%%b%%100000
if %nu% EQU 0 @echo %nu%&endlocal&goto :EOF
set OK=N
set list=\{MT\}
for /f "Tokens=1-4" %%a in ('net share %sn%') do (
 call :who %%a %%b %%c %%d
@echo %nu% %list%
goto :EOF
if "%1" EQU "Caching" set OK=N&goto :EOF
if "%OK%" EQU "Y" goto who1
if "%1" NEQ "Users" goto :EOF
set OK=Y
if \{%1\}==\{\} goto :EOF
if "%list%" EQU "\{MT\}" (
 set list=%1
 ) ELSE (
 set list=%list% %1
goto who1

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.