Jump to content

How to read just the data from a registry value?


Recommended Posts

Posted

Is there a way to set one registry value with the data from another within a cmd file?

Here's what I have:

HKEY_CLASSES_ROOT\.jpg
(Default) REG_SZ original_default_data

Here's what I need:

HKEY_CLASSES_ROOT\.jpg
(Default) REG_SZ EmberImage
BeforeEmberImage REG_SZ original_default_data

To make the changes, I need to get the original data from the (Default) value possibly into an environment variable.

REG QUERY HKCR\.jpg /ve returns too much information:

! REG.EXE VERSION 3.0

HKEY_CLASSES_ROOT\.jpg
<NO NAME> REG_SZ NeroPhotoSnapViewer.Files.jpg

I could also do this by renaming (Default) to BeforeEmberImage but I can't find a way to do that. REG COPY copies the entire key, not just the (Default) value.

I'd really like to do this in a simple cmd file without getting into vbs scripts, etc. Any suggestions?

Thanks.

Ray


Posted

This is not a one size fits all solution.

You cannot use this for all keys and values, many keys would require more values to be backed up and their structure would be different.

Here is an NT command script, it uses as in your example REG.EXE, which is not available by default in any pre-XP Windows OS.

@ECHO OFF&SETLOCAL
SET "N_=EmberImage"
SET "K_=HKLM\SOFTWARE\Classes\.jpg"&SET "V_=Pre_%N_%"
FOR /F "SKIP=3 TOKENS=2,3 DELIMS= " %%a IN ('REG QUERY %K_% /ve') DO (
SET "_=/t %%a /d "%%b"")
ECHO:REG ADD %K_% /v %V_% %_%
ECHO:REG ADD %K_% /ve /d "%N_%" /f
PAUSE

The code does not contain sufficient checks/debugging for potential errors and is made only as an example to the questions originator. The code as is does not actually make registry changes, just echo's the potential changes to the console window.

Note: DELIMS=<TAB> not a series of spaces!

I hope it serves its purpose for you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...