# Solved: Adding Registry Entry as Decimal



## scrfix (May 3, 2009)

I am using Reg.exe.

When I add the registry entry, it stores it as a hexidecimal. In my code, I actually have a variable instead of the 123456. Is there a way to write this to store it as a decimal?


```
REG ADD "HKLM\Software\MyCo" /v Data /t REG_DWORD /d 123456
```


----------



## TheOutcaste (Aug 8, 2007)

The REG_DWORD type is a hexadecimal type. Your command does enter the decimal value. Registry Editor will show it as 0x0001e240 (123456)
A reg query will return 0x1E240 though.
If you need it displayed as a decimal number by a Reg Query, you'd need to use the REG_SZ type.

Jerry


----------



## scrfix (May 3, 2009)

*Update 06-26-09*
Nevermind Jerry. I figured it out. I had the Do set %var% instead of Do set var.

*Old Data*
Thanks Jerry.

I have one other question. I am attempting to extract that data as well for my testing but I am doing something wrong.


```
:: Add the registry entry 123456 to the registry
REG ADD "HKLM\Software\MyCo" /v Data /t REG_SZ /d 123456
 
:: Extract that data out and store it into %_Q%
For /F "Tokens=2*" %%a In ('Reg query "HKLM\Software\MyCo" /v Data') Do set _Q=%%b
 
:: Show me the extracted data
Echo Registry Key Data: %_Q%
```


----------



## TheOutcaste (Aug 8, 2007)

Your Set statement in the For loop is trying to set %_Q% instead of _Q


```
For /F "Tokens=2*" %%a In ('Reg query "HKLM\Software\MyCo" /v Data') Do set _Q=%%b
```
I use this to get data from a single reg query:

```
For /F "Tokens=3 skip=2" %%a In ('Reg query "HKLM\Software\MyCo" /v Data') Do set _Q=%%a
```
This skips the 1st two lines that reg query outputs, then directly accesses the 3rd item, which will be the value.

Jerry


----------

