JSI Tip 8397. How can a batch script determine the number of users with active connections to a server share?

If you open a CMD.EXE window, and type RMTShare \\ServerName\ShareName, like rmtshare \\jsi001\Users, you receive a display similar to:

Share name        \\jsi001\Users
Path              D:\Users
Maximum users     No limit
Users             7
        \Everyone  :  FULL CONTROL
The command completed successfully.
To extract the number of users in a batch file, use:
for /f "Tokens=1,2" %%t in ('RMTShare \\ServerName\ShareName^|FIND "Users"') do (
 if "%%t" EQU "Users" set /a conusers=1000000%%u%%1000000
In this example, the conusers numeric environment variable will be set to 7.

NOTE: The exact case of Users is required.

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.