Search code examples
windows64-bitwindows-8.1

Exporting Entire Registry To Relative Path


Using the following code

REGEDIT /E C:\output.reg

A registry dump file is created in C directory. It overwrites automatically when a file with the same name exists. When I try changing the output directory to relative path like this

REGEDIT /E output.reg

it wouldn't work.

No file is created but processing takes just as long as usually. Which code can export the whole registry using relative path?

Like requested, the .bat code including debug code:

ECHO %CD%
REGEDIT /E output.reg
PAUSE

Command line output:

C:\Users\Username\Desktop\New_folder>ECHO C:\Users\Username\Desktop\New_folder
C:\Users\Username\Desktop\New_folder

C:\Users\Username\Desktop\New_folder>REGEDIT /E output.reg

C:\Users\Username\Desktop\New_folder>PAUSE
Press any key to exit . . .

Folder before (and after) .bat file execution:


Solution

  • The syntax of the command given in your question is already fine. If you supply a relative path for the output file name then the file will be created relative to the current working directory. This is easily verified from an interactive command prompt.

    Whatever is going wrong with your batch script, the problem is not as you have currently surmised. Some of the more obvious explanations include:

    1. The working directory is not what you think it is. Verify it by adding debug code to your script to emit the working directory.
    2. The file is locked for some reason and so regedit cannot write to the file.
    3. You don't have sufficient rights to write to the working directory.

    Update

    Thanks a lot for your question update. I tried to re-create your scenario (I'm on Windows 7 but I doubt that matters) and indeed I find the same issue as you. The command works fine from an interactive console window, but not when executing in a batch script.

    I've no idea why this is, but here a simple enough workaround is to supply a full path:

    REGEDIT /E %cd%\output.reg