Chris Stauffer at myITForum.com

You want me to do What?

Syndication

News

Links to blogs i like

Links

ZTI Hal Detect Script

Attachments dont seem to be working so here is a copy of the new ZTI_HalDetect1.2.vbs that i wrote.

Hope it posts ok since nothing else is today.

'******************************************************************************

'//////////////////////////////////////////////////
'//
'// Script File:
'//
'//   ZTIHalDetect.vbs
'//
'//   This script updates sysprep.inf With correct HAL Type
'//   The Reference (master) computer should be built from
'//   an Advanced ACPI computer
'//
'//   Use this script for WIM images (Imagex, OSD, WDS)
'//   Script Written by: Johan Arwidmark
'//   Edited/Logging added by: Chris Stauffer
'//////////////////////////////////////////////////

Const ForReading = 1, ForWriting = 2, ForAppending = 8
set oWshShell= wscript.createobject("wscript.shell")
'Get System Drive
Set objShell = WScript.CreateObject ("WScript.Shell")
strSystemDrv = objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
Wscript.Echo "System Drive: " & vbTab & strSystemDrv

WScript.Echo "Start Hal Check"

Set oFSO= CreateObject("Scripting.FileSystemObject")
' setup script for logging
Set oLog = CreateObject("Scripting.FileSystemObject")
sDate = Date
StrDate = DatePart("m",sDate) & "." & DatePart("d",sDate)
StrLogDir = strSystemDrv & "\MININT\SMSOSD\OSDLOGS\"
Set fLog = oLog.OpenTextFile(Strlogdir & "ZTI_HAL_Check." & strDate & ".log", ForWriting, True)

fLog.WriteLine "Start Hal Check"
flog.Writeling "System Drive: " & vbTab & strSystemDrv
' Customize the local sysprep.inf file based on the HAL type

Call UpdateSysprepinf ()

' Done, quit.

if err Then
    LogFileAppend "I got an error. It was error number: " & err.number & " and the description was " & err.description
    err.clear
end If

fLog.WriteLine "Finished Hal Check"

WScript.Quit

Sub UpdateSysprepinf ()

   ' Find out the HAL type
strsysprep = strSystemDrv & "\sysprep\sysprep.inf"

    sHalType = oWshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Enum\Root\ACPI_HAL\0000\HardwareID")
 
 strHalType = sHalType(0)
 
    fLog.WriteLine "Hal type Is: " & Strhaltype

   If sHalType(0) = "acpiapic" Then

 if oWshShell.Environment.item("NUMBER_OF_PROCESSORS") = 1 Then

       WriteIni strsysprep, "Unattended", "UpdateUPHAL", "ACPIAPIC_UP,%WINDIR%\Inf\Hal.inf"
 
   fLog.WriteLine "Number of Processors Is one."
   fLog.WriteLine "Hal type changed To: ACPIAPIC_UP"
 
 Else
  WriteIni strsysprep, "Unattended", "UpdateHAL", "ACPIAPIC_MP,%WINDIR%\Inf\Hal.inf"
  
  fLog.WriteLine "Number of Processors is more than one." 
     fLog.WriteLine "Hal type changed To: ACPIAPIC_MP"

 end If

   ElseIf sHalType(0) = "acpiapic_up" Then

 WriteIni strsysprep, "Unattended", "UpdateUPHAL", "ACPIAPIC_UP,%WINDIR%\Inf\Hal.inf"

 fLog.WriteLine "Hal type changed To: ACPIAPIC_UP"

   ElseIf sHalType(0) = "acpiapic_mp" Then

 WriteIni strsysprep, "Unattended", "UpdateHAL", "ACPIAPIC_MP,%WINDIR%\Inf\Hal.inf"

 fLog.WriteLine "Hal type changed To: ACPIAPIC_MP"

   End If


End Sub

Function ReadIni(file, section, item)

    ReadIni = ""
    file = Trim(file)
    item = Trim(item)
    Set ini = oFSO.OpenTextFile( file, 1, True)

    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 )

 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 = oFSO.GetParentFolderName(file) & "\" & oFSO.GetTempName

 Set read_ini = oFSO.OpenTextFile( file, 1, True, TristateFalse )
 Set write_ini = oFSO.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 item_exists = False Then
    write_ini.WriteLine line
    write_ini.WriteLine item & "=" & myvalue
    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
      write_ini.WriteLine itemtrimmed & "=" & myvalue
      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 Then ' section doesn't exist
  write_ini.WriteLine
  write_ini.WriteLine "[" & section & "]"
  write_ini.WriteLine itemtrimmed & "=" & myvalue
 End If

 read_ini.Close
 write_ini.Close
        If oFSO.FileExists(file) Then
            oFSO.DeleteFile file, True
        End If
        oFSO.CopyFile temp_ini, file, True
 oFSO.DeleteFile temp_ini, True
 
End Sub

Function LogfileAppend(sLogMsg)
    ON ERROR GOTO 0
     Dim iRetVal, fptr
     If Not objFSO.FileExists(sLogFile) Then
         ObjFSO.CreateTextFile(sLogFile)
     End If
     Set fptr = objFSO.OpenTextFile(sLogFile, 8, True)
     fptr.writeline(sLogMsg)
     fptr.close
End Function

 

 

Published Monday, April 23, 2007 1:08 PM by cstauffer
Filed under: ,

Comments

No Comments