banner



how to find the domain

6 Answers 6

Try:

                echo %USERDOMAIN%                              

or

                echo %USERDNSDOMAIN%                              

If that still doesn't work, you can try using systeminfo:

                systeminfo | findstr /B /C:"Domain"                              

answered Aug 29 '12 at 8:49

2

  • the smart quotes in "Domain" will make it fail to grep the string

    Feb 11 '19 at 9:29

You can run below command on command prompt:

              set user                          

It gives you a lot more information related to domain in addition to the name of domain as shown in below snapshot:

  1. User DNS Domain
  2. User Domain
  3. User Domain Roaming Profile
  4. User Name
  5. User Profile

enter image description here

Important Note: Domain on which your computer is registered might not be same as the domain on which the logged-in user is registered. Please read about transitivity and direction in domain trust to know how a user registered in one domain can login to a computer on another domain.

answered Feb 11 '19 at 7:06

The %USERDOMAIN% and the network computer domain can be different. The systeminfo command will get the right answer but it is SLOW! Here is a solution I've used:

              @REM + find the computer domain name  FOR /F "usebackq tokens=*" %%a IN (`ipconfig /all`) DO (      @((ECHO %%a | findstr /i /c:"Primary Dns Suffix") && SET _str=%%a) > NUL 2>&1  )  FOR /F "tokens=2 delims=:" %%a IN ("%_str%") do SET _computerDomain=%%a  SET _computerDomain=%_computerDomain: =%   SET _fqdn=%COMPUTERNAME%.%_computerDomain%                          

answered Sep 6 '13 at 17:43

@Mike: fine solution - but I had some problems with it in a multi-language enviroment. I have German and English servers.

I changed your script to use wmic.exe :

              @REM + Find the computer domain name @echo off FOR /F "usebackq tokens=*" %%a IN (`wmic.exe COMPUTERSYSTEM GET DOMAIN /Value`) DO (       @((ECHO %%a | findstr /i /c:"Domain=") && SET _str=%%a) > NUL 2>&1 ) FOR /F "tokens=2 delims=^=" %%a IN ("%_str%") do SET _computerDomain=%%a SET _computerDomain=%_computerDomain: =% SET _fqdn=%COMPUTERNAME%.%_computerDomain% echo %_fqdn%                          

Thx for your idea

Scott

19.7k 43 gold badges 59 silver badges 111 bronze badges

answered Mar 26 '14 at 20:00

One line is enough to get the domain using a local user:

              FOR /F "usebackq tokens=2 delims==" %%a IN (`wmic.exe COMPUTERSYSTEM GET DOMAIN /Value ^|find /i "domain"`) DO set _computerDom=%%a                          

answered Jul 14 '15 at 10:18

I just want to add my own solution just in case someone needs a fast way to do it.

My approach is using registry to get domain info:

              reg query "HKLM\System\CurrentControlSet\Services\Tcpip\Parameters" /v "Domain"                          

answered yesterday

New contributor

muzzol is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Not the answer you're looking for? Browse other questions tagged windows linux windows-7 or ask your own question.

how to find the domain

Source: https://superuser.com/questions/468217/how-to-get-domain-name-in-windows-using-command/1685549

Posted by: rogersnabowle.blogspot.com

0 Response to "how to find the domain"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel