Using Browstat.exe from \SUPPORT\TOOLS\SUPTOOLS.MSI on the Windows CD-ROM, I have scripted WorkGroup.bat to return the list of computer names in your workgroup (or domain).

NOTE: In a single segment LAN, you can run Browstat.exe on any computer. If your LAN has multiple segments, run it on the browse master.

The syntax for using WorkGroup.bat is:

for /f "Tokens=*" %%c in ('workgroup') do (
 call :DoSomething %%c
)
WorkGroup.bat contains:
@echo off
for /f "Tokens=2" %%a in ('browstat VIEW Transport^|find "\Device\"') do (
 for /f "Tokens=1" %%b in ('browstat VIEW %%a^|findstr /L /B "\\"') do (
  @echo %%b
 )
)
If you always want to strip the leading \\, WorkGroup.bat would contain:
@echo off
for /f "Tokens=2" %%a in ('browstat VIEW Transport^|find "\Device\"') do (
 for /f "Skip=2 Tokens=1 Delims=\ " %%b in ('browstat VIEW %%a') do (
  call echo %%b
 )
)