Batch / REG QUERY get the path of found value












1















I am trying to make a batch file, that finds a specific interface (their name vary from computer to computer = query). To find the interface I use a specific IP that is under that interface as a value.
The code here can find the interface in question based on the IP i insert into "IP-ADDRESS".



But my ultimate goal is to based on this search add two registry values into this interface, and therefore I need the path.



How do I get the path into a variable based on the search below?



for /f "tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces /s /f "IP-ADDRESS"') do set Myvar=%%b

ECHO %Myvar%
PAUSE


Thank you in advance!










share|improve this question

























  • Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

    – LotPings
    Nov 16 '18 at 15:43











  • Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

    – Wille Kreutzman
    Nov 16 '18 at 16:37
















1















I am trying to make a batch file, that finds a specific interface (their name vary from computer to computer = query). To find the interface I use a specific IP that is under that interface as a value.
The code here can find the interface in question based on the IP i insert into "IP-ADDRESS".



But my ultimate goal is to based on this search add two registry values into this interface, and therefore I need the path.



How do I get the path into a variable based on the search below?



for /f "tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces /s /f "IP-ADDRESS"') do set Myvar=%%b

ECHO %Myvar%
PAUSE


Thank you in advance!










share|improve this question

























  • Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

    – LotPings
    Nov 16 '18 at 15:43











  • Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

    – Wille Kreutzman
    Nov 16 '18 at 16:37














1












1








1








I am trying to make a batch file, that finds a specific interface (their name vary from computer to computer = query). To find the interface I use a specific IP that is under that interface as a value.
The code here can find the interface in question based on the IP i insert into "IP-ADDRESS".



But my ultimate goal is to based on this search add two registry values into this interface, and therefore I need the path.



How do I get the path into a variable based on the search below?



for /f "tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces /s /f "IP-ADDRESS"') do set Myvar=%%b

ECHO %Myvar%
PAUSE


Thank you in advance!










share|improve this question
















I am trying to make a batch file, that finds a specific interface (their name vary from computer to computer = query). To find the interface I use a specific IP that is under that interface as a value.
The code here can find the interface in question based on the IP i insert into "IP-ADDRESS".



But my ultimate goal is to based on this search add two registry values into this interface, and therefore I need the path.



How do I get the path into a variable based on the search below?



for /f "tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces /s /f "IP-ADDRESS"') do set Myvar=%%b

ECHO %Myvar%
PAUSE


Thank you in advance!







batch-file regedit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:40









Squashman

8,65131933




8,65131933










asked Nov 16 '18 at 15:28









Wille KreutzmanWille Kreutzman

62




62













  • Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

    – LotPings
    Nov 16 '18 at 15:43











  • Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

    – Wille Kreutzman
    Nov 16 '18 at 16:37



















  • Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

    – LotPings
    Nov 16 '18 at 15:43











  • Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

    – Wille Kreutzman
    Nov 16 '18 at 16:37

















Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

– LotPings
Nov 16 '18 at 15:43





Are you sure about the dash in IP-ADDRESS ? Also "tokens=5* doesn't seem right usually the 2nd is the type REG_DWORD/_SZ/_MULTISZand the 3rd the value.

– LotPings
Nov 16 '18 at 15:43













Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

– Wille Kreutzman
Nov 16 '18 at 16:37





Ah yeah, token=5 is wrong, I was just experimenting, had 3 from the beginning, wrong copypaste.

– Wille Kreutzman
Nov 16 '18 at 16:37












2 Answers
2






active

oldest

votes


















0














The following batch-file returns here:



> Q:Test20181116SO_53340832.cmd
IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}


It uses "tokens=1,2*" and /v IPADDRESS without dash.



:: Q:Test20181116SO_53340832.cmd
@Echo off & SetLocal EnableExtensions EnableDelayedExpansion

Set "Key=HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
Set "Val=IPADDRESS"

For /f "tokens=1,2*" %%A in (
'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
) Do if /i "%%A" neq "%Val%" (rem must be HKEY
Set "Interface=%%A"
) Else (
Echo %VAL%:%%C on interface:!Interface:%Key%=!
)





share|improve this answer































    0














    Here's one possibility for you:



    @Echo Off
    Set "RKP=HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
    Set "RVD=172.26.193.3"
    Set "RKC="

    For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
    ) Do If Not Defined RKC Set "RKC=%%A}"

    If Not Defined RKC Exit /B

    Rem show the variable and value for five seconds
    Set RKC
    Timeout 5 >Nul





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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%2fstackoverflow.com%2fquestions%2f53340832%2fbatch-reg-query-get-the-path-of-found-value%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The following batch-file returns here:



      > Q:Test20181116SO_53340832.cmd
      IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}


      It uses "tokens=1,2*" and /v IPADDRESS without dash.



      :: Q:Test20181116SO_53340832.cmd
      @Echo off & SetLocal EnableExtensions EnableDelayedExpansion

      Set "Key=HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
      Set "Val=IPADDRESS"

      For /f "tokens=1,2*" %%A in (
      'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
      ) Do if /i "%%A" neq "%Val%" (rem must be HKEY
      Set "Interface=%%A"
      ) Else (
      Echo %VAL%:%%C on interface:!Interface:%Key%=!
      )





      share|improve this answer




























        0














        The following batch-file returns here:



        > Q:Test20181116SO_53340832.cmd
        IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}


        It uses "tokens=1,2*" and /v IPADDRESS without dash.



        :: Q:Test20181116SO_53340832.cmd
        @Echo off & SetLocal EnableExtensions EnableDelayedExpansion

        Set "Key=HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
        Set "Val=IPADDRESS"

        For /f "tokens=1,2*" %%A in (
        'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
        ) Do if /i "%%A" neq "%Val%" (rem must be HKEY
        Set "Interface=%%A"
        ) Else (
        Echo %VAL%:%%C on interface:!Interface:%Key%=!
        )





        share|improve this answer


























          0












          0








          0







          The following batch-file returns here:



          > Q:Test20181116SO_53340832.cmd
          IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}


          It uses "tokens=1,2*" and /v IPADDRESS without dash.



          :: Q:Test20181116SO_53340832.cmd
          @Echo off & SetLocal EnableExtensions EnableDelayedExpansion

          Set "Key=HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
          Set "Val=IPADDRESS"

          For /f "tokens=1,2*" %%A in (
          'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
          ) Do if /i "%%A" neq "%Val%" (rem must be HKEY
          Set "Interface=%%A"
          ) Else (
          Echo %VAL%:%%C on interface:!Interface:%Key%=!
          )





          share|improve this answer













          The following batch-file returns here:



          > Q:Test20181116SO_53340832.cmd
          IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}


          It uses "tokens=1,2*" and /v IPADDRESS without dash.



          :: Q:Test20181116SO_53340832.cmd
          @Echo off & SetLocal EnableExtensions EnableDelayedExpansion

          Set "Key=HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
          Set "Val=IPADDRESS"

          For /f "tokens=1,2*" %%A in (
          'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
          ) Do if /i "%%A" neq "%Val%" (rem must be HKEY
          Set "Interface=%%A"
          ) Else (
          Echo %VAL%:%%C on interface:!Interface:%Key%=!
          )






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 17:13









          LotPingsLotPings

          18.7k61532




          18.7k61532

























              0














              Here's one possibility for you:



              @Echo Off
              Set "RKP=HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
              Set "RVD=172.26.193.3"
              Set "RKC="

              For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
              ) Do If Not Defined RKC Set "RKC=%%A}"

              If Not Defined RKC Exit /B

              Rem show the variable and value for five seconds
              Set RKC
              Timeout 5 >Nul





              share|improve this answer




























                0














                Here's one possibility for you:



                @Echo Off
                Set "RKP=HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
                Set "RVD=172.26.193.3"
                Set "RKC="

                For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
                ) Do If Not Defined RKC Set "RKC=%%A}"

                If Not Defined RKC Exit /B

                Rem show the variable and value for five seconds
                Set RKC
                Timeout 5 >Nul





                share|improve this answer


























                  0












                  0








                  0







                  Here's one possibility for you:



                  @Echo Off
                  Set "RKP=HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
                  Set "RVD=172.26.193.3"
                  Set "RKC="

                  For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
                  ) Do If Not Defined RKC Set "RKC=%%A}"

                  If Not Defined RKC Exit /B

                  Rem show the variable and value for five seconds
                  Set RKC
                  Timeout 5 >Nul





                  share|improve this answer













                  Here's one possibility for you:



                  @Echo Off
                  Set "RKP=HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces"
                  Set "RVD=172.26.193.3"
                  Set "RKC="

                  For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
                  ) Do If Not Defined RKC Set "RKC=%%A}"

                  If Not Defined RKC Exit /B

                  Rem show the variable and value for five seconds
                  Set RKC
                  Timeout 5 >Nul






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 17:15









                  CompoCompo

                  15.8k3926




                  15.8k3926






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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%2fstackoverflow.com%2fquestions%2f53340832%2fbatch-reg-query-get-the-path-of-found-value%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







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini