Posts Tagged USMT

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, http://t3chn1ck.wordpress.com
' COMMENT : 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
'==========================================================================
Option Explicit

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("C:\ResetBGInfo.txt") Then
 oFSO.CreateTextFile "C:\ResetBGInfo.txt"
End If
Set oFile = oFSO.OpenTextFile ("C:\ResetBGInfo.txt", 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
 

 

 

,

Leave a Comment

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, http://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

 

,

Leave a Comment

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:

  1. Edit MigUser.xml
  2. Find section with comment “This component migrates Desktop files”
  3. Within the objectSet of “<include filter=’MigXmlHelper.IgnoreIrrelevantLinks()’>”, change the pattern type line to the below:

    <pattern type=”File”>%CSIDL_DESKTOP%\* [*.lnk]</pattern>

  4. Save the MigUser.xml (of course!)

 

 

 

 

3 Comments

Excluding Users using USMT 4.0 in SCCM SP2

When it comes to backing up user data with USMT 4.0 [hardlinking] in SCCM, there are a few things that most people will want to do.  Such as excluding local computer accounts and excluding domain user profiles older than XX days.  It took a couple of days to get this figured out since there was no one blog post or forum topic which seemingly discussed both of these options. 

First things first, read this excellent blog post on How to use USMT 4 hardlinking in a Configuration Manager 2007 Task Sequence

Now, USMT uses Scanstate.exe and Loadstate.exe to backup and restore users [respectively].  Local users can be excluded using switch /ue and old domain user profiles can be excluded using switch /uel.  However, both of these switches cannot be used at the same time because of a precedence order.  For more information, read Understanding USMT 4.0 Behavior with UEL and UE.   So, to exclude local users and old domain users, set task sequence variables

  • OSDMigrateAdditionalCaptureOptions = /nocompress /hardlink /uel:30 (or however many days you want it to be)
  • OSDMigrateAdditionalRestoreOptions = /nocompress /hardlink /ue:%computername%\*

But there is also an undocumented problem.  SCCM adds to the Scanstate/Loadstate parameters, specifically adding the /all switch which says to backup/restore ALL USERS.  This completely goes against being able to use the /ue and/or the /uel switches and will cause scanstate/loadstate to fail!!  So what must be done to fix the problem is to

  1. Select the step to Capture User Files and Settings
  2. Select option “Customize how user profiles are captured”
  3. Click the Files… button
  4. Add files MigUser.xml, MigApp.xml
  5. Repeat the above steps for Restore User Files and Settings

Updated 8/16 – USMT Best Practices states to not use MigUser.xml and MigDocs.xml together, so I’ve removed MigDocs from step 4.

3 Comments

Follow

Get every new post delivered to your Inbox.

Join 39 other followers