在LTI中使用脚本修改XP镜像的HAL属性

原文地址: [url]http://myitforum.com/cs2/blogs/jhuston/archive/2007/08/09/hal-replacement-in-bdd.aspx[/url]
 
HAL问题一直是困惑XP部署的一个难题,不同的硬件信息导致HAL不同,使得一个镜像常常无法在其他机器上使用。类似于万能Ghost的修改方法,直接在应用镜像后修改HAL文件来,是这个脚本的核心。
 
脚本放入scripts目录里,添加到ts中的postinstall里
 
本来想贴原文翻译的,可实在太简单了,就直接贴出脚本好了
 
updatehal.wsf
 
<job id="UpdateHAL">
<script language=VBScript src="ZTIUtility.vbs" />
<script language=vBScript>
 'This script will update the HAL and NTOSKRNL files to be consistent with the architecture
 'of the target device, regardless of the source device used when building the image
 Dim sHalType, Processors, oWMI, sHalCmd, sKrnlCmd, sSource, sBuild, lBuildMajor
 
 oLogging.CreateEntry "UpdateHAL.wsf initialized.", LogTypeInfo
 
 'The first test is if this is a WIM image file (in which case IMAGESIZE > 0).  If it is not,
 'then the installation is from a set of flat files which will automatically use the correct
 'HAL.  In most cases, installation from a flat file source is only done when building a
 'Windows XP or Windows 2003 image for deployment.
 If oEnvironment.Item("IMAGESIZE") = 0 Then
  oLogging.CreateEntry "This is a flat-file installation.  No HAL replacement is necessary.", LogTypeInfo
 Else
 
  'The second test is to only modify the HAL for Windows XP and Windows 2003 images, not
  'for Windows Vista.  Windows Vista handles HAL differences automatically and does not
  'need this type of operation.
  sBuild = oEnvironment.Item("IMAGEBUILD")
  lBuildMajor = CLng(Left(sBuild,InStr(sBuild,".")-1))
  
  If lBuildMajor = 5 Then
   oLogging.CreateEntry "This is a version 5 kernel and we will need to update the HAL", LogTypeInfo
  
   'Get the HAL type from the registry (from Windows PE).  This will tell us if we are running on
   'a PIC or an APIC chipset.
   oLogging.CreateEntry "Configuring HAL replacement", LogTypeInfo
   sHalType = oShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Enum\Root\ACPI_HAL\0000\HardwareID")
   oLogging.CreateEntry "Windows PE is using HAL " & sHalType(0), LogTypeInfo
   
   'Get the number of CPUs from WMI to determine if we should use a uniprocessor HAL/KERNEL or a
   'multiprocessor HAL/KERNEL.
   Set oWMI = GetObject("winmgmts://./root/cimv2")
   Set Processors = oWMI.InstancesOf("Win32_Processor")
   oLogging.CreateEntry "There are " & Processors.Count & " CPU(s) installed", LogTypeInfo
   
   'Set the sSource path based on the processor architecture (x86 vs x64/AMD64).  Note that we
   'make an assumption that the OS is installed in the C:\WINDOWS directory.  The Source subdirectory
   'was created during the image build process (it is there by default).
   oLogging.CreateEntry "We are using a " & oEnvironment.Item("ARCHITECTURE") & " class processor", LogTypeInfo
   If oEnvironment.Item("ARCHITECTURE") = "X86" Then
    sSource = "C:\Windows\Source\i386\"
   Else
    sSource = "C:\Windows\Source\amd64\"
   End If
   
   'Based on the HAL that Windows PE is using, update SYSPREP.INF and configure the commandlines to
   'replace the HAL.DLL and NTOSKRNL.EXE files with the correct versions.
   Select Case lCase(sHalType(0))
   
    'This is the PIC chipset (which is always uniprocessor)
    Case "acpipic", "acpipic_up"
     'Add the UpdateUPHAL command to the Sysprep.inf file.
     oUtility.WriteINI "C:\Sysprep\Sysprep.inf", "Unattended", "UpdateUPHAL", """ACPIPIC_UP,%WINDIR%\Inf\Hal.inf"""
     oLogging.CreateEntry "Updated SYSPREP.INF to replace HAL with uniprocessor PIC HAL", LogTypeInfo
     
     'Configure the EXPAND command lines for the correct HAL and KERNEL files for PIC/Uniprocessor
     If oEnvironment.Item("ARCHITECTURE") = "X86" Then
      sHalCmd = sSource & "EXPAND.EXE " & sSource & "HALACPI.DL_ C:\WINDOWS\System32\HAL.DLL"
     Else
      sHalCmd = sSource & "EXPAND.EXE " & sSource & "HAL.DL_ C:\WINDOWS\System32\HAL.DLL"
     End If
     sKrnlCmd = sSource & "EXPAND.EXE " & sSource & "NTOSKRNL.EX_ C:\WINDOWS\System32\NTOSKRNL.EXE"
     
    'This is the APIC chipset
    Case "acpiapic", "acpiapic_up"
     'Usually, Windows PE will load the uniprocessor APIC files even when there are more than one
     'CPU installed.  Branch based on the number of CPUs inventoried by WMI to load the correct
     'set of files.
     If Processors.Count > 1 Then
      'Add the UpdateHAL command to the Sysprep.inf file.
      oUtility.WriteINI "C:\Sysprep\Sysprep.inf", "Unattended", "UpdateHAL", """ACPIAPIC_MP,%WINDIR%\Inf\Hal.inf"""
      oLogging.CreateEntry "Updated SYSPREP.INF to replace HAL with multiprocessor APIC HAL", LogTypeInfo
      
      'Configure the EXPAND command lines for the correct HAL and KERNEL files for APIC/Multiprocessor
      If oEnvironment.Item("ARCHITECTURE") = "X86" Then
       sHalCmd = sSource & "EXPAND.EXE " & sSource & "HALMACPI.DL_ C:\WINDOWS\System32\HAL.DLL"
      Else
       sHalCmd = sSource & "EXPAND.EXE " & sSource & "HAL.DL_ C:\WINDOWS\System32\HAL.DLL"
      End If
      sKrnlCmd = sSource & "EXPAND.EXE " & sSource & "NTKRNLMP.EX_ C:\WINDOWS\System32\NTOSKRNL.EXE"
      
     Else
      'Add the UpdateUPHAL command to the Sysprep.inf file.
      oUtility.WriteINI "C:\Sysprep\Sysprep.inf", "Unattended", "UpdateUPHAL", """ACPIAPIC_UP,%WINDIR%\Inf\Hal.inf"""
      oLogging.CreateEntry "Updated SYSPREP.INF to replace HAL with uniprocessor APIC HAL", LogTypeInfo
      
      'Configure the EXPAND command lines for the correct HAL and KERNEL files for APIC/Uniprocessor
      If oEnvironment.Item("ARCHITECTURE") = "X86" Then
       sHalCmd = sSource & "EXPAND.EXE " & sSource & "HALAACPI.DL_ C:\WINDOWS\System32\HAL.DLL"
      Else
       sHalCmd = sSource & "EXPAND.EXE " & sSource & "HAL.DL_ C:\WINDOWS\System32\HAL.DLL"
      End If
      sKrnlCmd = sSource & "EXPAND.EXE " & sSource & "NTOSKRNL.EX_ C:\WINDOWS\System32\NTOSKRNL.EXE"
     End If
     
    'This is the APIC chipset for multiple processors
    Case "acpiapic_mp"
     'Add the UpdateHAL command to the Sysprep.inf file.
     oUtility.WriteINI "C:\Sysprep\Sysprep.inf", "Unattended", "UpdateHAL", """ACPIAPIC_MP,%WINDIR%\Inf\Hal.inf"""
     oLogging.CreateEntry "Updated SYSPREP.INF to replace HAL with multiprocessor APIC HAL", LogTypeInfo
 
     'Configure the EXPAND command lines for the correct HAL and KERNEL files for APIC/Multiprocessor
     If oEnvironment.Item("ARCHITECTURE") = "X86" Then
      sHalCmd = sSource & "EXPAND.EXE " & sSource & "HALMACPI.DL_ C:\WINDOWS\System32\HAL.DLL"
     Else
      sHalCmd = sSource & "EXPAND.EXE " & sSource & "HAL.DL_ C:\WINDOWS\System32\HAL.DLL"
     End If
     sKrnlCmd = sSource & "EXPAND.EXE " & sSource & "NTKRNLMP.EX_ C:\WINDOWS\System32\NTOSKRNL.EXE"
     
   End Select
   
   'Execute the EXPAND command lines to actually use the correct HAL and NTOSKRNL files based on the
   'chipset and number of processors.
   oLogging.CreateEntry "Expanding correct HAL.DLL and NTOSKRNL.EXE files for this machine", LogTypeInfo
   oUtility.RunWithHeartbeat sHalCmd
   oUtility.RunWithHeartbeat sKrnlCmd
  
  Else
   'This is not a version 5 OS (meaning that it is Vista) and we won't be updating the HAL
   'for that (as it is supposed to be able to do that on it's own).
   oLogging.CreateEntry "This is a version " & CStr(lBuildMajor) & " kernel and updating the HAL is unncessary.", LogTypeInfo
  End If
 End If
</script>
</job>

你可能感兴趣的:(职场,休闲,hal,bdd,MDT)