Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Im trying to assing a reg key value to a batch variable however the only way i can think of doing it is by querying the value and using a for statement to assign the value into a variable....i know, i know, there has to be a better way.
I've looked into all the REG [command] commands and cant find anything to help me out.Any help would be greatly appreciated.

REG FIND HKLM\SOFTWARE SomeString > #
set /p var=<#
=====================================
If at first you don't succeed, you're about average.M2

I dont think i understand what you mean? There is no 'REG FIND' command or do you mean:
REG [command] [location] | FIND "[key name]" ??
I've looked into both and still cant find a solution.In detail my issue is with grabbing a reg string value of a full directory location under a key value. The only way i can think of is through some untidy for statements from a REG QUERY. Even so i still have drama's with some full URL locations that have spaces. For example C:\documents and settings\folder\folder2\.
Im thinking there has to be a better way to assign reg values of any type to variables in batch.....Any thoughts ????

Use REG QUERY to display the wished key value with the syntax posted by M2, i.e.
Reg Query your key > #
Set /P KeyVar=< #
Del #That stores the value into KeyVar by setting and deleting the temporary file #. To avoid temporary storage the only way is to code a For /F statement with no delims parameter as below
For /F "tokens=* delims=" %%A in ('REG QUERY ...') Do (
Set KeyVar=%%A)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |