Batch / REG QUERY get the path of found value
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
add a comment |
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
Are you sure about the dash inIP-ADDRESS
? Also"tokens=5*
doesn't seem right usually the 2nd is the typeREG_DWORD/_SZ/_MULTISZ
and 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
add a comment |
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
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
batch-file regedit
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 inIP-ADDRESS
? Also"tokens=5*
doesn't seem right usually the 2nd is the typeREG_DWORD/_SZ/_MULTISZ
and 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
add a comment |
Are you sure about the dash inIP-ADDRESS
? Also"tokens=5*
doesn't seem right usually the 2nd is the typeREG_DWORD/_SZ/_MULTISZ
and 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/_MULTISZ
and 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/_MULTISZ
and 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
add a comment |
2 Answers
2
active
oldest
votes
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%=!
)
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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%=!
)
add a comment |
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%=!
)
add a comment |
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%=!
)
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%=!
)
answered Nov 16 '18 at 17:13
LotPingsLotPings
18.7k61532
18.7k61532
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 16 '18 at 17:15
CompoCompo
15.8k3926
15.8k3926
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Are you sure about the dash in
IP-ADDRESS
? Also"tokens=5*
doesn't seem right usually the 2nd is the typeREG_DWORD/_SZ/_MULTISZ
and 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