Re: Running a vbscript during Post Install
- From: Johan Arwidmark <anonymous@xxxxxxxxxxxxxx>
- Date: Fri, 07 Jul 2006 16:17:13 +0200
I recommend using the preinstall phase for the disk partitioning stuff
and postinstall for updating sysprep.inf. In the postinstall phase,
the wim file has been layed down to disk.
regards
Johan Arwidmark
Microsoft MVP - Setup/Deployment
On 7 Jul 2006 06:17:24 -0700, "Tim" <nativemode@xxxxxxxxx> wrote:
Good Morning,
I've written a vbscript that I would like to run during the post
install phase of OSD. The script queries WMI to return the additional
partitions on the drive, and use diskpart to delete them. It's then
supposed update sysprep.inf to add ExtetndOEMPartition=1 if it needs
to.
If I run it during the preinstall phase, the partitions are removed,
but sysprep.inf does not appear to get updated. If I run it during
postinstall, nothing seems to happen at all, yet the logs show a return
code of 0.
So my questions are:
Is Postinstall the right time to do this?
Since I'm using ZTI, do I want to add my custom action for my script
before or after the zti script?
Is the %OSDTARGETDRIVE% variable available to my script?
Will this even work?
I'm pasting a copy of the script below in case anyone is interested.
Thanks in advance,
Tim
'==========================================================================
' NAME: PartitionAdjuster.vbs
' AUTHOR: Tim Sullivan (tim.sullivan@xxxxxxxxxxxxxxxx)
' DATE : 7/1/2006
' COMMENT: Script to use during the OSD process to remove partitions
after the C:
' drive, and extend the C: drive to all available space.
'
'
'==========================================================================
Option Explicit
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
'===================================
'Define objects
Dim strComputer
Dim objWMIService
Dim colPartitions, colDiskPartitions, objPartition
Dim objFSO
Dim objDiskPartFile, strDiskPartFile
Dim objLogFile, strLogFile
Dim strQueryResults
Dim WshShell
Dim regEx, strReplacement
Dim strDPErr
Dim objSysPrepFile, intLineFinder, strNextLine, strNewFile, Param,
Value, InsertValue
Dim sysPrepLoc
'=========================================================================
'Define any variables here.
'==================================
strComputer = "."
strLogFile =
"%OSDTARGETDRIVE%Minint\SMSOSD\OSDLogs\PartitionLogFile.log"
strDiskPartFile = "%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart\diskpart.txt"
'=========================================================================
'Functions to prepare both the log file.
CreateLogFile
'=========================================================================
'Here we gather our partitions, and write our diskpart.txt file.
'==================================
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer
& "\root\cimv2")
Set colDiskPartitions = objWMIService.ExecQuery("Select * from
Win32_DiskPartition where diskindex='0' and index > '0'")
'Check for the existence of returned files
strQueryResults = colDiskPartitions.Count
'If none are found, exit script.
If strQueryResults = 0 Then
objLogFile.WriteLine("No Partitions found beyond 0. Assuming single
disk. Exiting script!")
WScript.Quit
Else
objLogFile.Writeline("Determined partitions need to be modified.
Beginning...")
'==================================
'Create our diskpart file only if valid partitions to work with are
found.
objLogFile.WriteLine("Creating diskpart.txt file...")
CreateDiskPartFile
'==================================
For Each objPartition In colDiskPartitions
objLogFile.Writeline("Found the following partitions: " &
objPartition.Name)
objDiskpartFile.Writeline("select partition 2")
objDiskpartFile.WriteLine("delete partition")
Next
objDiskPartFile.WriteLine("exit")
objDiskPartFile.Close
'Shell out to execute diskpart.exe with our newly created answer file.
strDPErr = WshShell.Run("diskpart /s
%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart\diskpart.txt",0,True)
objLogFile.WriteLine("Diskpart execution result code is: " & strDPErr)
If strDPErr <> 0 Then
objLogFile.WriteLine("Diskpart execution error. Aborting script!")
WScript.Quit
Else
End If
'=========================================================================
'We now need to update sysprep.inf to allow for extending the OEM
partition.
'=========================================================================
objLogFile.Writeline("Modifying sysprep.inf to extend the C:
partitions...")
SysPrepFix
End If
objLogFile.WriteLine("Script execution complete!")
objLogFile.WriteLine("")
objLogFile.Close
'=========================================================================
'Functions and Sub's
'==================================
Function SysPrepFix
Set objSysPrepFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Sysprep\sysprep.inf", ForReading,
True)
Do Until objSysPrepFile.AtEndOfStream
strNextLine = objSysPrepFile.ReadLine
intLineFinder = InStr(strNextLine, "[Unattended]")
If intLineFinder <> 0 Then
strNextLine = strNextLine & vbCrLf & " ExtendOEMPartition=1"
End If
strNewFile = strNewFile & strNextLine & VbCrLf
Loop
objSysPrepFile.Close
Set objSysPrepFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Sysprep\sysprep.inf", ForWriting)
objSysPrepFile.WriteLine strNewFile
objSysPrepFile.Close
End Function
Function CreateLogFile
If objFSO.FileExists(strLogFile) Then
objFSO.DeleteFile(strLogFile)
Set objLogFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Minint\SMSOSD\OSDLogs\PartitionAdjuster.log",
ForAppending, True)
Else
Set objLogFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Minint\SMSOSD\OSDLogs\PartitionAdjuster.log",
ForAppending, True)
End If
objLogFile.WriteLine("Partition Adjuster Log File")
objLogFile.WriteLine("Author: Tim Sullivan")
objLogFile.Writeline("Date: 01.07.06")
objLogFile.WriteLine("Info: Script to adjust the partitions on the
first drive of a system. Used to end up with")
objLogFile.Writeline(" a system with a single logical C:
partition. Begins by gathering all paritions on disk")
objLogFile.WriteLine(" 0 greater than 1. Then writes an answer
file for the diskpart to use. Diskpart.exe is")
objLogFile.WriteLine(" then executed to remove the partitions.
Actions taken and partitions removed are logged")
objLogFile.Writeline(" here.")
objLogFile.Writeline("")
End Function
Function CreateDiskPartFile
If objFSO.FileExists(strDiskPartFile) Then
objFSO.DeleteFile(strDiskPartFile)
Set objDiskPartFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart\Diskpart.txt",
ForAppending, True)
Else
If objFSO.Folderexists("%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart") Then
Else
objFSO.CreateFolder("%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart")
End If
Set objDiskPartFile =
objFSO.OpenTextFile("%OSDTARGETDRIVE%Minint\SMSOSD\DiskPart\Diskpart.txt",
ForAppending, True)
End If
objDiskPartFile.WriteLine("Select Disk 0")
End Function
.
- Follow-Ups:
- References:
- Running a vbscript during Post Install
- From: Tim
- Running a vbscript during Post Install
- Prev by Date: Running a vbscript during Post Install
- Next by Date: Re: Running a vbscript during Post Install
- Previous by thread: Running a vbscript during Post Install
- Next by thread: Re: Running a vbscript during Post Install
- Index(es):
Relevant Pages
|
Loading