How to get domain name in Windows using command?












16















I need a similar command to Linux' domainname on Windows without using any third-party application.



Is there such a command?










share|improve this question















migrated from stackoverflow.com Aug 30 '12 at 12:02


This question came from our site for professional and enthusiast programmers.



















  • For information - domain name of computer and domain name of the logged-in user might not be same.

    – RBT
    Feb 11 at 9:17


















16















I need a similar command to Linux' domainname on Windows without using any third-party application.



Is there such a command?










share|improve this question















migrated from stackoverflow.com Aug 30 '12 at 12:02


This question came from our site for professional and enthusiast programmers.



















  • For information - domain name of computer and domain name of the logged-in user might not be same.

    – RBT
    Feb 11 at 9:17
















16












16








16


3






I need a similar command to Linux' domainname on Windows without using any third-party application.



Is there such a command?










share|improve this question
















I need a similar command to Linux' domainname on Windows without using any third-party application.



Is there such a command?







windows linux windows-7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 23 '15 at 13:36









Peter Mortensen

8,376166185




8,376166185










asked Aug 29 '12 at 8:45







Ricky











migrated from stackoverflow.com Aug 30 '12 at 12:02


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Aug 30 '12 at 12:02


This question came from our site for professional and enthusiast programmers.















  • For information - domain name of computer and domain name of the logged-in user might not be same.

    – RBT
    Feb 11 at 9:17





















  • For information - domain name of computer and domain name of the logged-in user might not be same.

    – RBT
    Feb 11 at 9:17



















For information - domain name of computer and domain name of the logged-in user might not be same.

– RBT
Feb 11 at 9:17







For information - domain name of computer and domain name of the logged-in user might not be same.

– RBT
Feb 11 at 9:17












5 Answers
5






active

oldest

votes


















24














Try:



echo %USERDOMAIN%


or



echo %USERDNSDOMAIN%


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



systeminfo | findstr /B /C:”Domain”





share|improve this answer



















  • 3





    %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

    – Sriniv
    Jan 18 '15 at 19:25











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

    – phuclv
    Feb 11 at 9:29



















1














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%





share|improve this answer































    1














    @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






    share|improve this answer

































      0














      One line is enought 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







      share|improve this answer

































        0














        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.






        share|improve this answer


























          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f468217%2fhow-to-get-domain-name-in-windows-using-command%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown
























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          24














          Try:



          echo %USERDOMAIN%


          or



          echo %USERDNSDOMAIN%


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



          systeminfo | findstr /B /C:”Domain”





          share|improve this answer



















          • 3





            %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

            – Sriniv
            Jan 18 '15 at 19:25











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

            – phuclv
            Feb 11 at 9:29
















          24














          Try:



          echo %USERDOMAIN%


          or



          echo %USERDNSDOMAIN%


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



          systeminfo | findstr /B /C:”Domain”





          share|improve this answer



















          • 3





            %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

            – Sriniv
            Jan 18 '15 at 19:25











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

            – phuclv
            Feb 11 at 9:29














          24












          24








          24







          Try:



          echo %USERDOMAIN%


          or



          echo %USERDNSDOMAIN%


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



          systeminfo | findstr /B /C:”Domain”





          share|improve this answer













          Try:



          echo %USERDOMAIN%


          or



          echo %USERDNSDOMAIN%


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



          systeminfo | findstr /B /C:”Domain”






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 29 '12 at 8:49









          Jon LinJon Lin

          735818




          735818








          • 3





            %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

            – Sriniv
            Jan 18 '15 at 19:25











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

            – phuclv
            Feb 11 at 9:29














          • 3





            %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

            – Sriniv
            Jan 18 '15 at 19:25











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

            – phuclv
            Feb 11 at 9:29








          3




          3





          %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

          – Sriniv
          Jan 18 '15 at 19:25





          %Userdomain% would give the domain of the user, not necessarily same as the domain name of the computer. windows-commandline.com/find-domain-name-command-line

          – Sriniv
          Jan 18 '15 at 19:25













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

          – phuclv
          Feb 11 at 9:29





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

          – phuclv
          Feb 11 at 9:29













          1














          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%





          share|improve this answer




























            1














            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%





            share|improve this answer


























              1












              1








              1







              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%





              share|improve this answer













              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%






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 6 '13 at 17:43









              MikeMike

              111




              111























                  1














                  @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






                  share|improve this answer






























                    1














                    @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






                    share|improve this answer




























                      1












                      1








                      1







                      @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






                      share|improve this answer















                      @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







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 26 '14 at 21:18









                      Scott

                      16.1k113990




                      16.1k113990










                      answered Mar 26 '14 at 20:00









                      BernhardBernhard

                      111




                      111























                          0














                          One line is enought 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







                          share|improve this answer






























                            0














                            One line is enought 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







                            share|improve this answer




























                              0












                              0








                              0







                              One line is enought 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







                              share|improve this answer















                              One line is enought 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








                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jul 14 '15 at 10:34









                              suspectus

                              3,70162031




                              3,70162031










                              answered Jul 14 '15 at 10:18









                              BrockyBrocky

                              1




                              1























                                  0














                                  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.






                                  share|improve this answer






























                                    0














                                    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.






                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      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.






                                      share|improve this answer















                                      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.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Feb 11 at 9:08

























                                      answered Feb 11 at 7:06









                                      RBTRBT

                                      164216




                                      164216






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Super User!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f468217%2fhow-to-get-domain-name-in-windows-using-command%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          How to make a Squid Proxy server?

                                          Is this a new Fibonacci Identity?

                                          Touch on Surface Book