Set Variable for REG QUERY Result

H

Henry Stockbridge

Hi,

I am creating a batch file that will detect the value for a particular
key. I want to then pass that value into a variable and process
accordingly.
::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
::
Set DefaultMDW=
::
reg query HKLM\SOFTWARE\Microsoft\Office\8.0\Access\Jet\3.5\Engines /v
SystemDB
::
:: If result contains the string "C:\WINDOWS\system32\SYSTEM.MDW",
then set
:: the variable to "System32", otherwise set the variable to "Other"
::
If %DefaultMDW%==System32 GOTO xxxx
If %DefaultMDW%==Other GOTO yyyy
:yyyy
Echo Unable to update system
Pause
Exit
:xxxx
copy CODE GOES HERE
pause
exit
:::::::::::::::::::::::::::::::::::::::::::::::::::

Any help you can lend would be appreciated.

Henry
 
D

David Candy

for /f "skip=4 tokens=1" %A in ('reg query "HKCR\.txt\shellnew" /v nullfile') Do echo %A
 
H

Henry Stockbridge

Thanks for the help. I must have typed something wrong. The returned
value is the Value Name, not the Value Data. Here is the revised code
and result:

@echo off
set %%A=
for /f "skip=4 tokens=1" %%A in ('reg query
HKLM\SOFTWARE\Microsoft\Office\8.0\Access\Jet\3.5\Engines /v SystemDB')
Do echo %%A
pause

SystemDB
Press any key to continue . . .

Henry
 
D

David Candy

I don't have that key. So I can't test it. That why I showed it to you on another (and shorter) key.

But I chose a key with empty data.

The 1,2,3 auto assigns 1 to %A (cos that the variable we specified), 2 to %B (because it is 1 + A = B), and 3 to %C (because 1 + B =C)

for /f "skip=4 tokens=1,2,3" %A in ('reg query "HKCR\.txt\shellnew" /v nullfile') Do echo %C
 
H

Henry Stockbridge

Thanks for the help. I am almost there! I can now successfully obtain
the value data for the value name. However, when I try to assign its
value to a variable, the variable never gets changed to -1. Might it
be possible the value is case sensitive, or that there are non-printing
characters (Space, Tab...) Here is the new code:

set securityfile=0
for /f "skip=4 tokens=3" %%A in ('reg query
HKLM\SOFTWARE\Microsoft\Office\8.0\Access\Jet\3.5\Engines /v SystemDB')
Do If %%A=="C:\WINDOWS\SYSTEM32\SYSTEM.MDW" set securityfile=-1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top