The only way that I know to do that is to run a "reg load" command and point it to the ntuser.dat for each user. The main problem is that the registry gets loaded as a subkey of HKLM. You can programmatically make changes, but if you run a program that references HKCU, that won't work.
Here's a script that displays every users wallpaper. You can add code to change the value.
# Refer to this site
# https://devblogs.microsoft.com/scripting/update-or-add-registry-key-value-with-powershell/
cls
# First test loaded hives.
$AllUsers = Get-ChildItem REGISTRY::HKEY_USERS
foreach ($u in $Allusers) {
$u.Name
$r = "REGISTRY::$($u.name)\Control Panel\Desktop"
$wp = (get-itemproperty -path $r -name Wallpaper -ErrorAction SilentlyContinue).wallpaper
if ($wp) {
$wp # Display wallpaper file name
# TODO: Here is where you test to see if the value needs changed or not and make the change.
} else {
"Wallpaper not found."
}
""
}
# Step 2 is to load each ntuser.dat using "reg load"
# Note that this registry cannot be referenced as HKEY_CURRENT_USER
# This script will load it into HKEY_LOCAL_MACHINE\ThisUser
$users = Get-ChildItem -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
foreach ($u in $users ) {
""
$r = "registry::" + $u.name
$ntuser = (get-itemproperty -path $r -name ProfileImagePath).ProfileImagePath
$ntuser = $ntuser + "\ntuser.dat"
$ntuser
if ((test-path -Path $ntuser)) {
} else {
"No user registry"
continue
}
$output = reg.exe load HKLM\ThisUser $ntuser 2>&1
if ($LastExitCode -ne 0) {
"Didn't work, user must be logged on."
#$output
$output = reg.exe unload HKLM\ThisUser 2>&1
continue
}
$r = "HKLM:\Thisuser\Control Panel\Desktop"
$wp = (get-itemproperty -path $r -name Wallpaper -ErrorAction SilentlyContinue).wallpaper
if ($wp) {
$wp # Display wallpaper file name
# TODO: Here is where you test to see if the value needs changed or not and make the change.
} else {
"Wallpaper not found."
}
$output = reg.exe unload HKLM\ThisUser 2>&1
}