Skip to content

Instantly share code, notes, and snippets.

@SightSpirit
Created December 31, 2021 21:30
Show Gist options
  • Save SightSpirit/e902233ff656d9659ca8dfd7e67c976b to your computer and use it in GitHub Desktop.
Save SightSpirit/e902233ff656d9659ca8dfd7e67c976b to your computer and use it in GitHub Desktop.
Template for batch file to import registry keys from a local file into another user's hive
:: THIS FILE WILL NOT RUN PROPERLY UNTIL YOU ADAPT IT TO YOUR USE CASE. (file paths, etc.)
:: Replace instances of "[...]" with relevant paths.
::
:: This template is in the public domain. Attribute to Eden Biskin if desired.
::
@ECHO Off
ECHO Step 1: Attempting to load other account's hive...
REG LOAD HKU\temp "C:\Users\[other username]\NTUSER.DAT" >nul
IF %ERRORLEVEL% EQU 1 GOTO loadfail
IF %ERRORLEVEL% NEQ 1 GOTO loadgood
:loadfail
ECHO Step 1 failure: failed to mount NTDATA into online registry
ECHO Press any key to exit...
PAUSE >nul
EXIT
:loadgood
ECHO Step 1 complete.
ECHO:
ECHO Step 2: Backing up relevant keys...
REG EXPORT HKU\temp\[path to parent of shallowest key you are changing] "C:\Users\[other username]\keys.bak.reg" /Y >nul
ECHO Step 2 complete.
ECHO:
ECHO Step 3: Attempting to import registry keys from file...
REG IMPORT "[path to .reg file you are importing]" >nul 2>&1
IF %ERRORLEVEL% EQU 1 GOTO impofail
IF %ERRORLEVEL% NEQ 1 GOTO happyend
:impofail
ECHO Step 3 failure: failed to import registry keys
ECHO:
ECHO Unloading hive...
REG UNLOAD HKU\temp >nul
ECHO Hive unloaded. Script FAILED. Press any key to exit...
PAUSE >nul
EXIT
:happyend
ECHO Step 3 complete. THIS STORY IS HAPPY END.
ECHO:
ECHO Unloading hive...
REG UNLOAD HKU\temp >nul
ECHO Hive unloaded. Press any key to exit...
PAUSE >nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment