SCCM-OSD-Registry-DevicePath

SCCM-OSD-Registry-DevicePath

 

‘ //***************************************************************************

‘ //*************************************************************************** 

‘//—————————————————————————-

‘//

‘// Global constant and variable declarations

‘//

‘//—————————————————————————- 

Option Explicit 

Dim iRetVal

DIM objRegistry

DIM strComputer

Dim objFSO, vDriverPaths

strComputer = “.”

Set objRegistry = GetObject(“winmgmts:” & strComputer & “rootdefault:StdRegProv”)

‘//—————————————————————————-

‘// End declarations

‘//—————————————————————————- 

‘//—————————————————————————-

‘// Main routine

‘//—————————————————————————- 

On Error Resume Next

iRetVal = ZTIProcess

ProcessResults iRetVal

On Error Goto 0 

‘//—————————————————————————

‘//

‘// Function: ZTIProcess()

‘//

‘// Input: None

‘// 

‘// Return: Success – 0

‘// Failure – non-zero

‘//

‘// Purpose: Perform main ZTI processing

‘// 

‘//—————————————————————————

Function ZTIProcess() 

     iRetVal = Success 

     ZTIProcess = iRetval 

‘//—————————————————————————-

‘// custom code

‘//

Dim sTempHive

Dim sRegHive

Dim sSName, vSystemDrive

Dim RegPath, RegKey_Current

Dim iZTIRetValue

Dim oShell

Set oShell = WScript.CreateObject (“Wscript.Shell”)

sSName = oUtility.ScriptName

On Error Resume Next

vSystemDrive = oEnvironment.Item(“OSDisk”) ‘Refresh scenario variable only

If vSystemDrive = “” Then vSystemDrive = oEnvironment.Item(“OSPARTITION”) ‘Bare metal scenario variable only. OSPARTITION is a pre WIM dump variable

If vSystemDrive = “” Then vSystemDrive = oEnvironment.Item(“OSDTargetSystemDrive”) ‘Bare metal scenario variable only. OSDTargetSystemDrive is a POST WIM dump variable

On Error Goto 0

If UCase(WScript.Arguments.Named(“OS”)) = “WINXP” Then

‘—- For Windows XP only as PnP cannot traverse sub-folders —-

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

GetFiles (vSystemDrive & “Drivers”)

‘WScript.Echo vDriverPaths

ElseIf UCase(WScript.Arguments.Named(“OS”)) = “WIN7” Then

vDriverPaths = “;%SystemDrive%Drivers;”

Else

oLogging.CreateEntry sSName & “: OS switch not defined”,LogTypeInfo

Exit Function

End If

sTempHive = Chr(34) & “HKEY_LOCAL_MACHINETemp_HIVE” & Chr(34)

sRegHive = Chr(34) & vSystemDrive & “WindowsSystem32configSOFTWARE” & Chr(34)

iZTIRetValue=”1″

oLogging.CreateEntry sSName & “: Actions Start – Updating Default Profile”,LogTypeInfo

oLogging.CreateEntry sSName & “: Loading the Registry Hive”,LogTypeInfo

‘WScript.Echo “will run reg load ” & sTempHive & ” ” & sRegHive

oShell.run “reg load ” & sTempHive & ” ” & sRegHive

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to load the registry hive ” & sRegHive,LogTypeError

ZTIProcess=70

Exit Function

End If

wscript.sleep 3000

oLogging.CreateEntry sSName & “: Registry Hive Loaded to ” & sTempHive,LogTypeInfo

oLogging.CreateEntry sSName & “: Starting Registry Changes… “,LogTypeInfo

RegPath = “HKEY_LOCAL_MACHINETemp_HIVEMicrosoftWindowsCurrentVersion”

RegKey_Current = oShell.RegRead(RegPath & “DevicePath”)

oLogging.CreateEntry sSName & “: Adding Custom DriverPath”,LogTypeInfo

oshell.RegWrite RegPath & “DevicePath”, RegKey_Current & vDriverPaths, “REG_EXPAND_SZ”

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to update DevicePath”,LogTypeError

ZTIProcess=60

Exit Function

End If

oLogging.CreateEntry sSName & “: Successfully added ” & Chr(34) & vDriverPaths & Chr(34), LogTypeInfo

oLogging.CreateEntry sSName & “: Unloading Hive”,LogTypeInfo

oShell.run “reg unload ” & sTempHive

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to unload the registry hive”,LogTypeError

ZTIProcess=20

Exit Function

End If

Wscript.Sleep 3000

oLogging.CreateEntry sSName & “: Actions completed”,LogTypeInfo

iZTIRetValue=0

End function

Function GetFiles(FolderName)

Dim objFiles, objSubFolders, vSubfolder

Dim vFile, vFileName, vINFFolder, objFolder

Set objFolder = objFSO.GetFolder(FolderName)

Set objFiles = objFolder.Files

For Each vFile in objFiles  

vFileName = UCase(vFile.name)

If objFSO.GetExtensionName(vFileName) = “INF” Then

‘Wscript.Echo vFileName

vINFFolder = objFso.GetParentFolderName(FolderName & “” &  vFileName)

If vDriverPaths = “” Then

vDriverPaths = “;” & vINFFolder

Else

vDriverPaths = vDriverPaths & “;” & vINFFolder

End If

Exit For

End if

Next

‘Getting all subfolders

    Set objSubFolders = objFolder.SubFolders

For Each ObjFolder In ObjSubFolders

GetFiles(ObjFolder.Path)

Next

End Function

‘//

‘// End Custom Code

‘//—————————————————————————–


 

‘ //***************************************************************************

‘ //*************************************************************************** 

‘//—————————————————————————-

‘//

‘// Global constant and variable declarations

‘//

‘//—————————————————————————- 

Option Explicit 

Dim iRetVal

DIM objRegistry

DIM strComputer

Dim objFSO, vDriverPaths

strComputer = “.”

Set objRegistry = GetObject(“winmgmts:” & strComputer & “rootdefault:StdRegProv”)

‘//—————————————————————————-

‘// End declarations

‘//—————————————————————————- 

‘//—————————————————————————-

‘// Main routine

‘//—————————————————————————- 

On Error Resume Next

iRetVal = ZTIProcess

ProcessResults iRetVal

On Error Goto 0 

‘//—————————————————————————

‘//

‘// Function: ZTIProcess()

‘//

‘// Input: None

‘// 

‘// Return: Success – 0

‘// Failure – non-zero

‘//

‘// Purpose: Perform main ZTI processing

‘// 

‘//—————————————————————————

Function ZTIProcess() 

     iRetVal = Success 

     ZTIProcess = iRetval 

‘//—————————————————————————-

‘// custom code

‘//

Dim sTempHive

Dim sRegHive

Dim sSName, vSystemDrive

Dim RegPath, RegKey_Current

Dim iZTIRetValue

Dim oShell

Set oShell = WScript.CreateObject (“Wscript.Shell”)

sSName = oUtility.ScriptName

On Error Resume Next

vSystemDrive = oEnvironment.Item(“OSDisk”) ‘Refresh scenario variable only

If vSystemDrive = “” Then vSystemDrive = oEnvironment.Item(“OSPARTITION”) ‘Bare metal scenario variable only. OSPARTITION is a pre WIM dump variable

If vSystemDrive = “” Then vSystemDrive = oEnvironment.Item(“OSDTargetSystemDrive”) ‘Bare metal scenario variable only. OSDTargetSystemDrive is a POST WIM dump variable

On Error Goto 0

If UCase(WScript.Arguments.Named(“OS”)) = “WINXP” Then

‘—- For Windows XP only as PnP cannot traverse sub-folders —-

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

GetFiles (vSystemDrive & “Drivers”)

‘WScript.Echo vDriverPaths

ElseIf UCase(WScript.Arguments.Named(“OS”)) = “WIN7” Then

vDriverPaths = “;%SystemDrive%Drivers;”

Else

oLogging.CreateEntry sSName & “: OS switch not defined”,LogTypeInfo

Exit Function

End If

sTempHive = Chr(34) & “HKEY_LOCAL_MACHINETemp_HIVE” & Chr(34)

sRegHive = Chr(34) & vSystemDrive & “WindowsSystem32configSOFTWARE” & Chr(34)

iZTIRetValue=”1″

oLogging.CreateEntry sSName & “: Actions Start – Updating Default Profile”,LogTypeInfo

oLogging.CreateEntry sSName & “: Loading the Registry Hive”,LogTypeInfo

‘WScript.Echo “will run reg load ” & sTempHive & ” ” & sRegHive

oShell.run “reg load ” & sTempHive & ” ” & sRegHive

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to load the registry hive ” & sRegHive,LogTypeError

ZTIProcess=70

Exit Function

End If

wscript.sleep 3000

oLogging.CreateEntry sSName & “: Registry Hive Loaded to ” & sTempHive,LogTypeInfo

oLogging.CreateEntry sSName & “: Starting Registry Changes… “,LogTypeInfo

RegPath = “HKEY_LOCAL_MACHINETemp_HIVEMicrosoftWindowsCurrentVersion”

RegKey_Current = oShell.RegRead(RegPath & “DevicePath”)

oLogging.CreateEntry sSName & “: Adding Custom DriverPath”,LogTypeInfo

oshell.RegWrite RegPath & “DevicePath”, RegKey_Current & vDriverPaths, “REG_EXPAND_SZ”

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to update DevicePath”,LogTypeError

ZTIProcess=60

Exit Function

End If

oLogging.CreateEntry sSName & “: Successfully added ” & Chr(34) & vDriverPaths & Chr(34), LogTypeInfo

oLogging.CreateEntry sSName & “: Unloading Hive”,LogTypeInfo

oShell.run “reg unload ” & sTempHive

If Err0 Then 

oLogging.CreateEntry sSName & “: Failed to unload the registry hive”,LogTypeError

ZTIProcess=20

Exit Function

End If

Wscript.Sleep 3000

oLogging.CreateEntry sSName & “: Actions completed”,LogTypeInfo

iZTIRetValue=0

End function

Function GetFiles(FolderName)

Dim objFiles, objSubFolders, vSubfolder

Dim vFile, vFileName, vINFFolder, objFolder

Set objFolder = objFSO.GetFolder(FolderName)

Set objFiles = objFolder.Files

For Each vFile in objFiles  

vFileName = UCase(vFile.name)

If objFSO.GetExtensionName(vFileName) = “INF” Then

‘Wscript.Echo vFileName

vINFFolder = objFso.GetParentFolderName(FolderName & “” &  vFileName)

If vDriverPaths = “” Then

vDriverPaths = “;” & vINFFolder

Else

vDriverPaths = vDriverPaths & “;” & vINFFolder

End If

Exit For

End if

Next

‘Getting all subfolders

    Set objSubFolders = objFolder.SubFolders

For Each ObjFolder In ObjSubFolders

GetFiles(ObjFolder.Path)

Next

End Function

‘//

‘// End Custom Code

‘//—————————————————————————–

Leave a Comment