Demodave
Demodave

Reputation: 6632

How to get Data from a registry key value via command line

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?

Upvotes: 11

Views: 44624

Answers (1)

John Kens
John Kens

Reputation: 1679

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)

Upvotes: 8

Related Questions