[Tips] Add HKCU registry key with Setupcomplete.cmd

freMea

Member
If for any reasons, you prefer using setupcomplete.cmd script than the built-in dedicated section in NTLite, to reg key including HKCU, follow these steps.

Here is the structure in your sources folder
jylF3B.jpg

the setupcomplete.cmd must be in the Scripts folder and registry files in the reghack folder.

Here is an example of setupcomplete.cmd that will add some registry files.
Code:
:: To keep page layout, decorations and accents
:: always load and save this file with format
:: "OEM" alias "CP850" alias "DOS Latin 1"
:: with DOS line return
@echo off
cls
:: Needed for scripts run as admin to run in the script relative path
cd /d "%~dp0"

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: =====================================================================
:: --- SET VARIABLES
:: =====================================================================
:: some env variables relative to current user like %APPDATA% can NOT be used because
:: they don’t exist while setupcomplete is run.

:: save output to c:\custom Windows setup.log
set log="%SystemDrive%\custom Windows setup.log"

echo CHECK VALID VARIABLES DURING SETUP >> %log%
echo ================================== >> %log%
echo ALLUSERSPROFILE: %ALLUSERSPROFILE% >> %log%
echo CD: %CD% >> %log%
echo COMPUTERNAME: %COMPUTERNAME% >> %log%
echo OS: %OS% >> %log%
echo PROGRAMFILES: %PROGRAMFILES% >> %log%
echo SystemDrive: %SystemDrive% >> %log%
echo SystemRoot: %SystemRoot% >> %log%
echo TEMP: %TEMP% >> %log%
echo USERNAME: %USERNAME% >> %log%
echo WINDIR: %WINDIR% >> %log%
echo. >> %log%
echo Following variables should return nothing: >> %log%
echo USERDOMAIN: %USERDOMAIN% >> %log%
echo HOMEDRIVE: %HOMEDRIVE% >> %log%
echo APPDATA: %APPDATA% >> %log%
echo. >> %log%

echo ======================== >> %log%
echo START: SetupComplete.cmd >> %log%
echo ======================== >> %log%
:: ------------------------------
echo. >> %log%
echo Load this file with format "OEM" alias "CP850" alias "DOS Latin 1" >> %log%
echo. >> %log%
echo Working dir: %cd% >> %log%
echo. >> %log%
echo IMPORT REGISTRY FILES >> %log%
echo --------------------- >> %log%

REM SOME OS CUSTOMIZATIONS
CALL :RegImport "reghack\Custom HKLM.reg"
REM windows update and privacy policies
CALL :RegImport "reghack\My policies [Computer].reg"

echo. >> %log%
echo IMPORT HKCU (default user actually) >> %log%
echo ----------------------------------- >> %log%
echo. >> %log%
echo Load "C:\Users\Default\NTUSER.DAT" >> %log%
reg load "HKU\CurrentUsersDefault" "%SystemDrive%\Users\Default\NTUSER.DAT"
IF NOT !ErrorLevel!==0 (
    echo    █   FAILURE  >> %log%               
) else (
    echo    +   SUCCESS  >> %log%   

    REM SOME OS CUSTOMIZATIONS
    CALL :RegImport "reghack\Custom HKCU.reg"
    REM add japanese language in settings
    CALL :RegImport "reghack\add jap.reg"
    
    echo. >> %log%
    echo Unload "C:\Users\Default\NTUSER.DAT" to save >> %log%
    reg unload "HKU\CurrentUsersDefault"
    IF NOT !ErrorLevel!==0 (
        echo    █   FAILURE  >> %log%               
    ) else (
        echo    +   SUCCESS  >> %log%
    )   
)

echo. >> %log%
echo =========================================== >> %log%
echo END: SetupComplete.cmd >> %log%

exit /b

:: ---------------------------------------------------------------------
:: -- FUNCTIONS SECTION START
:: ---------------------------------------------------------------------
:: FUNCTION TO IMPORT A REG FILE
:: CALL :RegImport "param1"

:: param1 @path: "relative or absolute path\backupFile.reg"

:: example => CALL :RegImport "%backupFolder%\%regFileName%"

:RegImport
echo.>> %log%
echo     ╔════════════════════════════════════════════════════════════╗ >> %log%
echo       Import : "%~1" >> %log%
echo      ──────────────────────────────────────────────────────────── >> %log%

:: if the reg file to restore exists
if exist "%~1" (

    REG import "%~1" > nul 2>&1

    REM Success
    if !errorlevel! == 0 (
        echo    +   SUCCESS  >> %log%
        exit /b 0
    ) else (
    REM display error message if restauration fails
    echo    █   ERROR DURING IMPORTATION REGISTRY FILE   >> %log%
    echo        This command : REG import "%~1" >> %log%
    echo        returned an error. >> %log%
    echo. >> %log%
    echo        Some keys may be protected although >> %log%
    echo        it’s been executed as admin. >> %log%
    exit /b 1
    )

) else (
    REM display message if reg file doesn’t exist
    echo.>> %log%
    echo    █   REGISTRY FILE NOT FOUND  >> %log%
    echo        ─────────────────────── >> %log%
    echo. >> %log%
    echo        This file : "%~1" >> %log%
    echo        doesn’t exist. >> %log%
    echo. >> %log%
    exit /b 1
)
exit /b

Something very important. Here is a sample of reghack\Custom HKCU.reg. Notice some edit (search and replace) must be made to make it compatible with this import method because the default user hive is loaded in HKEY_USERS\CurrentUsersDefault

Code:
Windows Registry Editor Version 5.00
; Encode this this file as UTF-16 little endian
; *********************************************
; -------------------------------------------------------------------------------------
; Always use "HKEY_USERS\CurrentUsersDefault" instead of "HKEY_CURRENT_USER"
; -------------------------------------------------------------------------------------

; Print screen button opens the capture tool
[HKEY_USERS\CurrentUsersDefault\Control Panel\Keyboard]
"PrintScreenKeyForSnippingEnabled"=dword:00000001


I think you have an example of how this trick can be implemented in a setupcomplete method.
 
Correct me if i am wrong;

i only need to edit this part in my user hive regs ?

HKEY_USERS\CurrentUsersDefault\Control Panel\Keyboard
 
Sorry to dig the old thread, I have heard many people talk about this script, can someone give a brief description what it does ?
 
Correct me if i am wrong;

i only need to edit this part in my user hive regs ?

HKEY_USERS\CurrentUsersDefault\Control Panel\Keyboard
Sorry for the late answer. I think you figured it out now. When you export this key to a reg file, it will be
HKEY_CURRENT_USER\Control Panel\Keyboard

You only need to replace HKEY_CURRENT_USER with HKEY_USERS\CurrentUsersDefault
 
Sorry to dig the old thread, I have heard many people talk about this script, can someone give a brief description what it does ?
I can not tell more than the first post explains unless you have a more specific question. If you don’t understand what it does, it’s probably you don’t need it.
 
Back
Top