To read a path value for a specific registry key with a batch process

Source: Internet
Author: User

The command to query a registry key with a batch command is

REG QUERY ...

Specific usage information is entered in the Command line window

REG QUERY/?

Here we need to query a specific key-value, then use the following command

Reg  QUERY [reg PATH]/V [KEY]

As an example,

" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\110\tools\clientsetup " " Path "

The results appear as follows:

" hkey_local_machine\software\microsoft\microsoft SQL server\\tools\clientsetup"   "Path"hkey_local_machine\software\microsoft\microsoft SQL server\ \tools\clientsetup    Path    REG_SZ    C:\Program Files\Microsoft SQL Server\110\tools\binn\

We're going to take the red part out, notice that the reg batch command here is the output of two lines, and we're going to take the second half of the next line. We use for to take this part out. Let's start with the basic structure of for:

 for/F  "tokens=1,2 delims=:" %%a in  (' REG QUERY [Reg_path]'  do (    set"value1=%%a "     Set " value2=%%b "  )

The For loop handles the two lines that are taken out of the REG query, each of which is stored in the variable%%a, but uses tokens and delims,delims to specify the characters that divide the string, which is the ":" to split each line of string, tokens=1,2 Indicates that the first two columns after the split are removed, the column is saved in%%a, and the second column is saved in%%b (if there is a third column saved in%%c) ... Keep Looking at the example above.

echo off for/F"tokens=1,2 delims=:"%%ainch('reg QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL server\110\tools\clientsetup"/V "Path"')  Do(       Set "value1=%%a"Echo%value1%Set "value2=%%b"Echo%value2%)

The final variable value

value1 = Path REG_SZ C

value2 = \program Files\Microsoft SQL Server\110\tools\binn\

Connect the value1 first character (that is, the drive letter C) and the value2 to the middle by:

Set " value2=%value1:~-1%:%value2% "

  

To read a path value for a specific registry key with a batch process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.