Unattend files - Copy Profile


Jalopy

New member
Local time
6:52 PM
Posts
9
OS
Windows 11
I've noticed when this cmd prompt pops up, on what I'm pretty sure is the reg unload portion, I get an 'access denied'. From what I can tell, nothing is going awry on the installs, the profile is still copied. Should this concern me? Should I even be using copy profile nowadays? I swear I've read some posts somewhere that say it should be either not used, or avoided for some reason I don't remember.

Powershell:
# Read the below to script reason
# https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-copyprofile
# Load the hive
reg load "HKU\DefaultUser" 'C:\Users\Default\NTUSER.DAT'
# Delete the keys
Remove-Item -Path "Registry::HKU\DefaultUser\Software\Microsoft\Windows\Shell\Associations\FileAssociationsUpdateVersion" -ErrorAction SilentlyContinue
Remove-Item -Path "Registry::HKU\DefaultUser\Software\Microsoft\Windows\Shell\Associations\UrlAssociations" -ErrorAction SilentlyContinue
Remove-Item -Path "Registry::HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts" -ErrorAction SilentlyContinue
# Unload the hive
reg unload "HKU\DefaultUser"
 

My Computer My Computer

At a glance

Windows 11
OS
Windows 11
Computer type
PC/Desktop
This is a well-documented race condition, where PS hasn't committed any hive updates before the "reg unload" wants to do its work. Normally this is resolved by inserting a garbage collect command to flush memory:
Code:
# Unload the hive
[gc]::Collect()
reg unload "HKU\DefaultUser"

You don't see this problem running the same commands by hand. Because you're slower than the PS script.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
This is a well-documented race condition, where PS hasn't committed any hive updates before the "reg unload" wants to do its work. Normally this is resolved by inserting a garbage collect command to flush memory:
Code:
# Unload the hive
[gc]::Collect()
reg unload "HKU\DefaultUser"

You don't see this problem running the same commands by hand. Because you're slower than the PS script.
Neat. I'll add that to the script. Since you haven't told me otherwise I'll just assume that there is no inherent drawback to using Copy Profile, then.
 

My Computer My Computer

At a glance

Windows 11
OS
Windows 11
Computer type
PC/Desktop
My personal experience is some HKCU keys inserted into Default User's NTUSER.DAT don't always get inherited by a new user profile. It's supposed to by design, but in practice -- some keys are ignored. But the same keys work when imported after the first logon session.

You just have to perform some testing.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
Back
Top Bottom