I always use WinPE as the deployment, whether I'm using ghost,
altiris, ads or simply xcopy to lay down a sysprepped image.
In most cases you need to activate the disks using diskpart (assign a
driveletter) after laying down an image....
Here is a simple script that does hardware detect in Windows PE using
WMI and then updates sysprep.inf (the readini and writeini funtions
are "borrowed" from the BDD 2.5 zerotouchinstallation.vbs script)
' ********* Begin Script *****************
Option Explicit
' Declare the variables
Dim objWMI, objResults, objInstance, strModel, objFS
Dim strUP, strMP
' Initialize objects
Set objWMI = GetObject("winmgmts:")
set objFS = CreateObject("Scripting.FileSystemObject")
' Detect hardware using WMI
Set objResults = objWMI.InstancesOf("Win32_ComputerSystemProduct")
For each objInstance in objResults
If not IsNull(objInstance.Name) then
strModel = Trim(objInstance.Name)
End if
Next
' Find out sysprep values and update sysprep.inf
strUP = "ACPIAPIC_UP,%windir%\Inf\Hal.inf"
strMP = "ACPIAPIC_MP,%windir%\inf\hal.inf "
Select Case strModel
Case "SCENIC D"
WriteIni "c:\sysprep\sysprep.inf","Unattended","UpdateUPHAL",strUP
Case "ESPRIMO E"
WriteIni "c:\sysprep\sysprep.inf","Unattended","UpdateHal",strMP
Case "HP Compaq dc7600 Ultra-Slim Desktop"
WriteIni "c:\sysprep\sysprep.inf","Unattended","UpdateHal",strMP
Case Else
' Do nothing
End Select
Function ReadIni(file, section, item)
Dim line, equalpos, leftstring, ini
ReadIni = ""
file = Trim(file)
item = Trim(item)
Set ini = objFS.OpenTextFile( file, 1, False)
Do While ini.AtEndOfStream = False
line = ini.ReadLine
line = Trim(line)
If LCase(line) = "[" & LCase(section) & "]" Then
line = ini.ReadLine
line = Trim(line)
Do While Left( line, 1) <> "["
'If InStr( 1, line, item & "=", 1) = 1 Then
equalpos = InStr(1, line, "=", 1 )
If equalpos > 0 Then
leftstring = Left(line, equalpos - 1 )
leftstring = Trim(leftstring)
If LCase(leftstring) = LCase(item) Then
ReadIni = Mid( line, equalpos + 1 )
ReadIni = Trim(ReadIni)
Exit Do
End If
End If
If ini.AtEndOfStream Then Exit Do
line = ini.ReadLine
line = Trim(line)
Loop
Exit Do
End If
Loop
ini.Close
End Function
Sub WriteIni( file, section, item, myvalue )
Dim in_section, section_exists, item_exists, wrote
Dim itemtrimmed, read_ini, write_ini, temp_ini
Dim linetrimmed, line, equalpos, leftstring
in_section = False
section_exists = False
item_exists = ( ReadIni( file, section, item ) <> "" )
wrote = False
file = Trim(file)
itemtrimmed = Trim(item)
myvalue = Trim(myvalue)
temp_ini = objFS.GetParentFolderName(file) & "\" & objFS.GetTempName
Set read_ini = objFS.OpenTextFile( file, 1, True, False )
Set write_ini = objFS.CreateTextFile( temp_ini, False)
While read_ini.AtEndOfStream = False
line = read_ini.ReadLine
linetrimmed = Trim(line)
If wrote = False Then
If LCase(line) = "[" & LCase(section) & "]" Then
section_exists = True
in_section = True
ElseIf InStr( line, "[" ) = 1 Then
in_section = False
End If
End If
If in_section Then
If itemtrimmed = "" then
' Do nothing: we want to wipe the section
ElseIf item_exists = False Then
write_ini.WriteLine line
If myvalue <> "" then
write_ini.WriteLine item & "=" & myvalue
End if
wrote = True
in_section = False
Else
equalpos = InStr(1, line, "=", 1 )
If equalpos > 0 Then
leftstring = Left(line, equalpos - 1 )
leftstring = Trim(leftstring)
If LCase(leftstring) = LCase(item) Then
If myvalue <> "" then
write_ini.WriteLine itemtrimmed & "=" & myvalue
End if
wrote = True
in_section = False
End If
End If
If Not wrote Then
write_ini.WriteLine line
End If
End If
Else
write_ini.WriteLine line
End If
Wend
If section_exists = False and itemtrimmed <> "" Then
' section doesn't exist
write_ini.WriteLine
write_ini.WriteLine "[" & section & "]"
If myvalue <> "" then
write_ini.WriteLine itemtrimmed & "=" & myvalue
End if
End If
read_ini.Close
write_ini.Close
If objFS.FileExists(file) then
objFS.DeleteFile file, True
End if
objFS.CopyFile temp_ini, file, true
objFS.DeleteFile temp_ini, True
End Sub
' ********* End Script *****************
regards
Johan Arwidmark
Microsoft MVP - Setup/Deployment