JSI Tip 7176. How can I test if a computer is a logged on to a domain?

Jerold Schulman

September 11, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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=Nif defined UserDNSDomain set dom=Y

To define an environment variable that contains the domain or workgroup name:

set dom=Nif 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



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like