Month: June 2011
USMT workaround for BGInfo desktop wallpaper
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, https://t3chn1ck.wordpress.com ' 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. ' HISTORY : ' 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" Else 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 Next ' 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", "" Else oReg.SetStringValue HKLM, sTempHiveWallpaperKeyPath, "Wallpaper", sWallpaperFile End If oFile.WriteLine " => Set user profile: " & sProfileLCase oFile.WriteLine " Note: Wallpaper value = " & sWallpaperFile End Sub
Workaround for KB2444193 with USMT 4
There is a known issue when migrating to Windows 7 with USMT. If a computer is deployed using an AutoUnattend.xml, then after migrating a user to the new computer, when the user launches IE they receive the message “A program on your computer has corrupted your default search provider…“. One workaround is to have a script correct the SearchScope GUIDs for each user profile. The script that I have written (below) simply mounts each user profile hive, then deletes the registry tree for the SearchScopes. The effect is that when the user first launches IE 8, then it will pull the default Search Provider from HKLM defined in the deployed computer via AutoUnattend.
'========================================================================== ' NAME: DeleteUserIESearchProviders ' AUTHOR: Nick Moseley, https://t3chn1ck.wordpress.com ' COMMENT: Mounts user registry hives and deletes the IE Search Provider ' registry values. This is to fix the issue caused by KB2444193 ' HISTORY: ' 1.0 (06/23/2011) - Initial Script '========================================================================== Option Explicit Const ForAppending = 8 Const HKLM = &H80000002 Const sUserKey = "Software\Microsoft\Internet Explorer\SearchScopes" 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") ' Prompt if OK to continue Dim x x = msgbox ("Click OK to delete the IE Search Provider for all user profiles", vbOKCancel, "Fix IE Search Provider") If x<>1 Then WScript.Echo "Script Terminated" WScript.Quit End If '========================================================================== ' Begin log file etnries '========================================================================== If Not oFSO.FileExists("C:\DeleteSearchProvider.log") Then oFSO.CreateTextFile "C:\DeleteSearchProvider.log" End If Set oFile = oFSO.OpenTextFile ("DeleteSearchProvider.log", ForAppending, True) oFile.WriteLine "Delete IE Search Provider" oFile.WriteLine " => Began at " & Date & " " & Time oFile.WriteLine " => For each user profile, deleted HKCU\" & sUserKey '========================================================================== ' 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 Dim sHiveKeyPath 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" ElseIf sProfileLCase = "default" Then 'oFile.WriteLine " => Skipped user profile: default user" Else 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 sHiveKeyPath = sHiveName & "\" & sUserKey DeleteSubkeys (sHiveKeyPath) oFile.WriteLine " => Set user profile: " & sProfileLCase ' Unload user's profile hive sRegUnload = " UNLOAD HKLM\" & sHiveName oShell.Run sRegExe & sRegUnload, 0, True End If Next ' End logging oFile.WriteLine " => Completed at " & Date & " " & Time WScript.Echo "Script Completed" WScript.Quit (oFile.Close) Sub DeleteSubkeys(sTempHiveKeyPath) Dim aSubKeys, oSubKey oReg.EnumKey HKLM, sTempHiveKeyPath, aSubKeys If IsArray(aSubKeys) Then For Each oSubKey In aSubKeys DeleteSubkeys sTempHiveKeyPath & "\" & oSubKey Next End If oReg.DeleteKey HKLM, sTempHiveKeyPath End Sub
Excluding file types within MigUser.XML
For an upcoming upgrade of our computers, I had a request that during the user migration that only desktop shortcuts (.lnk) files be backed up and migrated and no other files. It took several failed attempts to get working correctly, but the process I finally found that works was to do the following:
- Edit MigUser.xml
- Find section with comment “This component migrates Desktop files”
- Within the objectSet of “<include filter=’MigXmlHelper.IgnoreIrrelevantLinks()’>”, change the pattern type line to the below:
<pattern type=”File”>%CSIDL_DESKTOP%\* [*.lnk]</pattern>
- Save the MigUser.xml (of course!)