JSI Tip 9230. How can a script retrieve all the local user names on my computer?

In tip 7964, I scripted GetUsers.bat to retieve all the user names in a domain.

I have scripted GetLclUsers.bat to retrieve all the local user names on a computer.

The syntax for using GetLclUsers.bat is:

\[call\] GetLclUsers

The output is displayed on the console, so you could pipe it to a file, or use it for subsequent processing:

for /f "Tokens=*" %%u in ('getlclusers') do (
 call :DoSomething "%%u"
goto :EOF
GetLclUsers.bat contains:
@echo off
for /f "Tokens=*" %%a in ('net user^|more +4^|find /i /v "The command completed successfully."') do (
 set line=%%a
 call :parse
goto :EOF
set short=%name%#
set short=%short:  =%
set short=%short: #=#%
set short=%short:#=%
@echo %short%
goto :EOF
set name=%line:~0,25%
call :strip
set name=%line:~25,25%
if not "%name%" EQU "" call :strip
set name=%line:~50,25%
if not "%name%" EQU "" call :strip

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.