Share via

reg load will create a new registry file??

Ashley Kwan 20 Reputation points
2026-04-12T08:28:50.8766667+00:00

I am trying to create a .bat file for modify registry. During debugging, I run the command "reg load HKLM\TempHive C:\Windows\System32\config\Softwarv1235". Surprisingly, The result is "The operation completed successfully", and a new file named "Softwarv1235" was created at that path.

By design, shouldn't reg load only load an existing hive file and return an error if the file does not exist? Is this a bug in reg load?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

  1. Tracy Le 7,480 Reputation points Independent Advisor
    2026-04-12T12:57:12.6833333+00:00

    Hi Ashley Kwan,

    You have stumbled upon a classic case of documentation lagging behind the actual system behavior. It is not a bug in the code, but rather an undocumented quirk of how Windows handles registry hives under the hood.

    When you execute reg load, the command-line tool eventually passes your request down to the core Windows Win32 APIs (specifically, functions like RegLoadAppKeyW). While the official documentation for reg.exe strictly states the file must exist, the underlying API is actually programmed to automatically create a brand-new, empty hive file if it doesn't find one at the specified path. The reg command simply inherits this native API behavior without explicitly documenting it.

    The takeaway for your scripting: Even though you successfully created a file this way, do not rely on it for production .bat files. Because it is undocumented for reg load, Microsoft could silently patch the command-line parser in a future update to strictly enforce the "file must exist" rule, which would immediately break your scripts.

    For bulletproof automation, stick to the documented contract: always use reg save to create the hive first, or copy an existing blank template file before attempting to load it.

    I hope this clears up the mystery for your debugging session! If this helped answer your question, please click "Accept Answer".

    Tracy.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Tracy Le 7,480 Reputation points Independent Advisor
    2026-04-14T02:22:15.6833333+00:00

    Hi Ashley Kwan,

    I just wanted to do a quick follow-up to see how your WinPE recovery script turned out. Were you able to successfully implement the IF EXIST validation block, and did it work as expected to catch any typos and prevent the creation of empty registry hives during your testing?

    If you need any more help fine-tuning your batch file or tackling other WinPE quirks, please don't hesitate to drop a comment. I'm always happy to help!

    Tracy.

    0 comments No comments

  2. Tracy Le 7,480 Reputation points Independent Advisor
    2026-04-12T18:21:48.9233333+00:00

    Hi Ashley Kwan,

    That typo actually saved you from a much bigger headache down the line! WinPE environments can be unforgiving, so discovering this "create-if-missing" quirk now is definitely a blessing in disguise.

    You are absolutely right—adding a simple file validation check before executing the reg load command is the safest way to bulletproof your script. You can easily do this by wrapping your command in a basic IF EXIST block in your .bat file:

    SET "HivePath=C:\windows\system32\config\software"
    IF NOT EXIST "%HivePath%" (
        ECHO ERROR: The registry hive file was not found at %HivePath%. Check for typos!
        EXIT /B 1
    )
    reg load HKLM\TempHive "%HivePath%"
    

    This ensures the script halts immediately and alerts you if the target file is missing or misspelled, rather than silently creating a useless, empty hive and proceeding with the rest of your recovery commands.

    Good luck with your WinPE recovery script! If you run into any other batch scripting hurdles, feel free to reach out.

    Tracy.

    0 comments No comments

  3. Q&A Assist
    2026-04-12T08:32:21.4633333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    reg load is documented as a tool that loads an already saved hive file into a registry key. The syntax and parameter description state that the <filename>:

    • “must be created in advance by using the reg save command”
    • “must have a .hiv extension”
    reg load <keyname> <filename>
    

    So, according to the official command-line documentation, reg load is intended to work only with an existing hive file and is not described as creating a new hive when the file is missing.

    In contrast, the Win32 API RegLoadAppKeyW explicitly documents that if the hive file does not exist, an empty hive file is created with the specified name:

    “If the file does not exist, an empty hive file is created with the specified name.”

    That “create-if-missing” behavior is clearly by design for RegLoadAppKeyW, but there is no such statement for the reg load command. For reg load, the documented contract is that the hive file already exists and was created by reg save.

    Given this, the behavior observed—reg load HKLM\TempHive C:\Windows\System32\config\Softwarv1235 reporting success and leaving behind a new file when Softwarv1235 did not previously exist—is not described in the reg load documentation and contradicts the statement that the file “must be created in advance.” From the perspective of the published docs, this should be treated as undocumented/implementation behavior rather than something to rely on.

    For scripting and automation, the safe assumption is:

    • Do not depend on reg load to create hive files.
    • Ensure the hive file is created first with reg save and then passed to reg load.

    If a scenario requires guaranteed creation of a new hive file when missing, the documented API that supports that pattern is RegLoadAppKeyW, not the reg load command.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.