Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:13:10+00:00 2026-06-02T19:13:10+00:00

I am trying to read a REG Value into an Environment Variable in a

  • 0

I am trying to read a REG Value into an Environment Variable in a BAT file. E.g.,

REG HKLM\SYSTEM\CurrentControlSet\Services\Eventlog /v ImagePath

I can get the entire output string of the REG command into an environment variable like this:

FOR /F "usebackq delims==" %%a in (`REG QUERY "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v ImagePath`) DO set ImagePath=%%a

However, this sets the environment variable to the entire line, i.e.,

ImagePath   REG_EXPAND_SZ   C:\Windows\system32\services.exe

I want the Environment Variable to consist only of the path portion, i.e.,

C:\Windows\system32\services.exe

Thanks for any tips.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:13:12+00:00Added an answer on June 2, 2026 at 7:13 pm
    for /f "tokens=2*" %%A in ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v ImagePath') DO set ImagePath=%%B
    

    The default delimiter is space and tab; no need to change it. TOKENS=2* stores the 2nd token in %%A and the remainder of the line in %%B.

    Concerning your original code – there is no benefit to using USEBACKQ in your situation. Also, your code would not preserve the entire line if it contained = because you used that as the delimiter.

    Answer to comment
    If you can rely on the fact that the path does not contain any spaces, then you can simply use “TOKENS=3” and save %%A. But I wouldn’t trust that. Instead, I would use

    for /f "tokens=2*" %%A in ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v ImagePath') DO (
      for %%F in (%%B) do (
        set ImagePath=%%F
        goto :break
      )
    )
    :break
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to read into an object the following XML file (can be changed) into
I have a reg file which I'm trying to read. There's a type dword
I'm trying to read a .doc file into a database so that I can
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
Iam trying to read a binary file to memory and pass the starting address
I am trying to read a CSV file with accented characters with Python (only
I am trying to read a binary file from a program that writes a
Trying to read in some information from the google maps api into my application
am trying to read a file (double values) with scanner and save the data
I am trying to read a log file with the content look like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.