Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

SCCM 2007 : change Background on error in Task Sequence

Publié le par damcuvelier

If there is an error on Task Sequence, you can change backround with this script.

Add the image that you want in the source as name “backgroundDefault.jpg”

script:

'--------------------------------------------------------
' Script pour Changer l'image de Backgroud
'
' Ce script permet de changer l'image de fond
'--------------------------------------------------------
On Error Resume Next
Dim oFSO, ModeTS, Here, WshShell, KeyPath, oENvTS
Dim DefaultBackGroundPath, PathBackDfltImg, ErrorPathImg, DefaultPath

' Gestion de la modification de l'attribut "lecture seule" des fichiers recopiés
Dim ObjoFSO
Const FileAttrReadOnly = 1
Set oFSO = CreateObject("Scripting.filesystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
ModeTS = False
Err.Clear
Set oENvTS = CreateObject("Microsoft.SMS.TSEnvironment")
If Err.Number = 0 Then
    ModeTS = True
    PathNameLog = oENvTS("_SMSTSLogPath") & "\_ChangeBackgroundImage.log"
Else
    ModeTS = False
    PathNameLog = "C:\temp" & "\_ChangeBackgroudImage.log"
End If
err.clear

LogTextToFile("Action : ERROR")

Here = left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)
DefaultPath = "C:\Windows\System32\oobe\info\backgrounds"
PathBackDfltImg = DefaultPath & "\backgroundDefaultBAK.jpg"
ErrorPathImg = DefaultPath & "\backgroundDefault.jpg"
KeyPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground"

'-------------------------------------------------------------------
'Actions
If oFSO.FolderExists("C:\Windows\System32\oobe\info") = False Then
    oFSO.CreateFolder("C:\Windows\System32\oobe\info")
    LogTextToFile("Creation de C:\Windows\System32\oobe\info")
End If
If oFSO.FolderExists("C:\Windows\System32\oobe\info\backgrounds") = False Then
    oFSO.CreateFolder("C:\Windows\System32\oobe\info\backgrounds")
    LogTextToFile("Creation de C:\Windows\System32\oobe\info\backgrounds")
End If
' Sauvegarde du fond d'ecran par defaut
If oFSO.FileExists(PathBackDfltImg) = False Then
    oFSO.CopyFile "C:\Windows\System32\oobe\background.bmp",PathBackDfltImg,True
    LogTextToFile("Sauvegarde du fond d'ecran par defaut (" & PathBackDfltImg & ")")
End If
' Copie de l'images d'erreur /Y
    oFSO.CopyFile Here & "\backgroundDefault.jpg",ErrorPathImg,True
    LogTextToFile("Copie de l'images d'erreur (" & Here & "\backgroundDefault.jpg" & ")")
' Activation de l'impage d'erreur
WshShell.RegWrite KeyPath , 1, "REG_DWORD"
LogTextToFile("Set registry : " & KeyPath)

' Gestion de l'attribut READ-ONLY lors de déploiement à partir d'image ISO - DefaultBackGroundPath
If oFSO.FileExists(DefaultBackGroundPath) = True Then
    Set ObjoFSO = oFSO.GetFile(DefaultBackGroundPath)
    If ObjoFSO.Attributes AND FileAttrReadOnly Then
        ObjoFSO.Attributes = ObjoFSO.Attributes XOR FileAttrReadOnly
    End If
End If

LogTextToFile("Terminé")

function LogTextToFile(strTextToLog)
    Dim objFileSystemObjectForLogfileAccess, objFile, objLogFile2,objLogFile , n
    Dim strFilenameWithoutExtension
    const intMaxFileSize = 2097152
    strFilenameWithoutExtension= left(PathNameLog ,len(PathNameLog)-4)
    On Error Resume Next
    Set objFileSystemObjectForLogfileAccess = CreateObject("Scripting.FileSystemObject")
    n = -1
    Set objFile = objFileSystemObjectForLogfileAccess.getfile(strFilenameWithoutExtension & ".log")
    If objFile.Size > intMaxFileSize Then
        Set objLogFile2 = objFileSystemObjectForLogfileAccess.getfile(strFilenameWithoutExtension & ".lo_")
        objLogFile2.Delete
        objFile.name = left(objFile.name, len(objFile.name)-1) & "_"
        objFile.close
    End If
    Set objLogFile = objFileSystemObjectForLogfileAccess.opentextfile(strFilenameWithoutExtension & ".log", 8, True)
    objLogFile.writeline Date & " - " & Time & " - """ & strTextToLog & """"
    objLogFile.Close
    Set objFile = Nothing
    Set objLogFile2 = Nothing
    set objLogFile = nothing
end Function

Commenter cet article