Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Name
  • Type
  • Data

I am trying to get the data from the value in command line how do I do this?

like image 824
Demodave Avatar asked Oct 17 '22 08:10

Demodave


1 Answers

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)
like image 144
John Kens Avatar answered Oct 21 '22 06:10

John Kens