Offline hives and NTUSER.DAT
Load, edit and unload a user's NTUSER.DAT, the Default profile and the hives of an offline Windows installation.
What NTUSER.DAT is
Each user profile folder holds NTUSER.DAT, the file behind that user's HKEY_CURRENT_USER. Windows loads it into HKU\<SID> at sign-in and unloads it at sign-out. Class registrations sit separately in %LOCALAPPDATA%\Microsoft\Windows\UsrClass.dat. The template for every new profile is C:\Users\Default\NTUSER.DAT.
While a user is signed in their NTUSER.DAT is locked: edit it through HKU\<SID> instead of loading the file.
Load, edit, unload with reg.exe
:: mount the Default profile under a temporary name
reg load HKU\DefaultUser C:\Users\Default\NTUSER.DAT
:: change what every NEW profile will get
reg add "HKU\DefaultUser\Control Panel\International" /v sShortDate /t REG_SZ /d dd/MM/yyyy /f
:: always unload when finished
reg unload HKU\DefaultUser
Use HKU or HKLM as the mount point and a name that doesn't already exist. Close Regedit windows and PowerShell sessions that are browsing the mounted key first, or unload fails with "Access is denied" because handles are still open.
The same with Regedit
- Select HKEY_USERS (or HKEY_LOCAL_MACHINE). Load Hive is greyed out anywhere else.
- File > Load Hive, pick the file (show hidden files: NTUSER.DAT is hidden), give it a temporary name.
- Edit under that name.
- Select the mounted key and File > Unload Hive.
The same with PowerShell
reg load HKU\TempUser 'C:\Users\jdoe\NTUSER.DAT' | Out-Null
try {
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty 'HKU:\TempUser\Software\Contoso' -Name Mode -Value 2
} finally {
[gc]::Collect(); [gc]::WaitForPendingFinalizers() # release .NET handles before unloading
reg unload HKU\TempUser | Out-Null
}
PowerShell keeps handles to keys it touched. The garbage collection call before reg unload avoids most "Access is denied" failures.
Change a setting for every existing user
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null
$profiles = Get-CimInstance Win32_UserProfile | Where-Object { -not $_.Special }
foreach ($p in $profiles) {
$hive = "HKU:\$($p.SID)"
$loaded = Test-Path $hive
if (-not $loaded) { reg load "HKU\$($p.SID)" "$($p.LocalPath)\NTUSER.DAT" | Out-Null }
New-Item "$hive\Software\Contoso" -Force | Out-Null
Set-ItemProperty "$hive\Software\Contoso" -Name Mode -Value 2
if (-not $loaded) { [gc]::Collect(); reg unload "HKU\$($p.SID)" | Out-Null }
}
For settings that must apply at each user's next sign-in, Group Policy (User Configuration) or Active Setup is usually cleaner than editing every hive.
An offline Windows installation
From WinPE, Windows RE or another OS with the disk attached, load the machine hives from <drive>:\Windows\System32\config:
reg load HKLM\OFFLINE_SYSTEM D:\Windows\System32\config\SYSTEM
reg load HKLM\OFFLINE_SOFTWARE D:\Windows\System32\config\SOFTWARE
:: offline there is no CurrentControlSet: read HKLM\OFFLINE_SYSTEM\Select\Current to find ControlSet00x
reg unload HKLM\OFFLINE_SOFTWARE
reg unload HKLM\OFFLINE_SYSTEM
Typical uses: disable a driver or service that makes the machine crash at boot, fix an RDP setting on a cloud VM you can't reach, or collect evidence.
References: reg load, reg unload, Registry hives.