Starting with Windows NT 5.0 (Windows 2000), the UserDNSDomain environment variable is populated with the DNS domain name when the user is logged on to a domain.

To test for the %UserDNSDomain% environment variable:

set dom=N                              if defined UserDNSDomain set dom=Y
To define an environment variable that contains the domain or workgroup name:
set dom=N                              if defined UserDNSDomain set dom=Y&set WORKGROUP=%UserDNSDomain%                              if "%dom%" EQU "N" For /F "tokens=3" %%i in ('Net Config Workstation^|Find /i "Workstation Domain  "') Do @Set WORKGROUP=%%i