USMT workaround for BGInfo desktop wallpaper

Posted on Updated on

If you use BGInfo on your computers and migrate a user’s profile to a new computer, you’ll soon discover that the BGInfo of the new computer is overlaying BGInfo from the old computer, creating a very ugly desktop wallpaper.  The reason for this is that once BGInfo executes, it generates a new image from what the user had previously set for themselves.  Fortunately, the original image file’s location is stored in the registry as well.  The below script that I created is designed to run prior to USMT (while no user’s are logged into Windows).  It essentially mounts each user’s registry hive, grabs the original file from the registry and then resets the Wallpaper value for that user.

There is one caveat to this process however.  If within USMT you’ve set /uel:X to excludes user profiles older than X number of days, using this script will cause those profiles to now be recently logged into.  So before using this script, be sure to cleanup any old user profiles that you do not want migrated.

' AUTHOR  : Nick Moseley,
' COMMENT : This corrects a problem with migrating the BGInfo wallpaper vs.
' the user's actual wallpaperfile. This script will parse all User profiles
' on the computer, load their HKCU hive, then set the appropriate registry
' keys to reset a user's background image.
' 1.0 (06/23/2011) - Initial script
' 1.1 (02/20/2013) - Added Const LogFile to quickly define location
Option Explicit

Const LogFile = "C:\Windows\Temp\ResetBGInfo.log"
Const ForAppending = 8
Const HKLM = &H80000002
Const sReadUserKey = "Software\Winternals\BGInfo"
Const sSetUserKey = "Control Panel\Desktop"
Const sStringValueName = "Wallpaper"

Dim oReg, oFSO, oFile, oUserSubkey, aUserProfiles, oShell
Dim sProfileLCase, sRegExe, sRegLoad, sRegUnload, sHiveName, sSubPath, sProfile, sValueName, sKeyPathUserProfiles, sValue, ReturnVal

Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")

' Begin log file etnries
If Not oFSO.FileExists(LogFile) Then
oFSO.CreateTextFile LogFile
End If
Set oFile = oFSO.OpenTextFile (LogFile, ForAppending, True)

oFile.WriteLine "Reset BGInfo values for all users for USMT"
oFile.WriteLine "  => Began at " & Date & " " & Time
oFile.WriteLine "  => For each user profile, set " & sStringValueName & " (string) to the user's Wallpaper settings in HKCU\" & sSetUserKey

' Begin configuration of existing user profiles
sValueName = "ProfileImagePath"
sKeyPathUserProfiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
sRegExe = "C:\Windows\system32\reg.exe"

oReg.EnumKey HKLM, sKeyPathUserProfiles, aUserProfiles

' Existing User Profiles
For Each oUserSubkey In aUserProfiles
sSubPath = sKeyPathUserProfiles & "\" & oUserSubkey
oReg.GetExpandedStringValue HKLM,sSubPath,sValueName,sValue

sProfile = Split(sValue, "\")
sProfileLCase = LCase(sProfile(2))

If sProfileLCase = "system32" Then
'oFile.WriteLine "  => Skipped user profile: system32"
ElseIf sProfileLCase = "localservice" Then
'oFile.WriteLine "  => Skipped user profile: localservice"
ElseIf sProfileLCase = "networkservice" Then
'oFile.WriteLine "  => Skipped user profile: networkservice"
ElseIf sProfileLCase = "serviceprofiles" Then
'oFile.WriteLine "  => Skipped user profile: serviceprofiles"
ElseIf sProfileLCase = "administrator" Then
'oFile.WriteLine "  => Skipped user profile: administrator"
sHiveName = "TempHive_" & sProfileLCase

' Load user's profile hive into a temp location
sRegLoad = " LOAD HKLM\" & sHiveName & " """ & sValue & "\ntuser.dat"""
oShell.Run sRegExe & sRegLoad, 0, True

' Call subroutine to change registry key
SetConfigUserHive (sHiveName)

' Unload user's profile hive
sRegUnload = " UNLOAD HKLM\" & sHiveName
oShell.Run sRegExe & sRegUnload, 0, True
End If

' End logging
oFile.WriteLine "  => Completed at " & Date & " " & Time
WScript.Quit (oFile.Close)

Sub SetConfigUserHive (sTempHive)
Dim sTempHiveKeyPath, sTempHiveWallpaperKeyPath, sWallpaperFile

' Path of registry keys
sTempHiveKeyPath = sTempHive & "\" & sReadUserKey
sTempHiveWallpaperKeyPath = sTempHive & "\" &  sSetUserKey

' Get BGInfo value
oReg.GetStringValue HKLM, sTempHiveKeyPath, "Wallpaper", sWallpaperFile

If sWallpaperFile="(None)" Or sWallpaperFile="" Then
oReg.SetStringValue HKLM, sTempHiveWallpaperKeyPath, "Wallpaper", ""
oReg.SetStringValue HKLM, sTempHiveWallpaperKeyPath, "Wallpaper", sWallpaperFile
End If

oFile.WriteLine "  => Set user profile: " & sProfileLCase
oFile.WriteLine "     Note: Wallpaper value = " & sWallpaperFile
End Sub


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s