I am trying to get the Data from a registry key value via command line
I can retrieve the value of a registry key using the following code
reg query HKCU\Software\[PATH_TO_MY_DIR] /v [KEY_NAME]
This works as expected and outputs three items:
I am trying to get the data from the value in command line how do I do this?
This can be done very simply using a FOR
loop along-side it's Token
System. Since reg query
will output the variables in a one two three
format, we can use tokens=3
to grab only the third item in the output.
From CMD:
for /F "tokens=3" %A in ('reg query "HKCU\Software\[PATH_TO_MY_DIR]" /v "[KEY_NAME]"') DO (Echo %A)
From BATCH:
for /F "tokens=3" %%A in ('reg query "HKCU\Software\[PATH_TO_MY_DIR]" /v "[KEY_NAME]"') DO (Echo %%A)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With