Skip navigation

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

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



Hide comments

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.
Publish