Zero Touch Installation Deployment Feature Team Guide

Appendix F: Sample User Exit Function

Published: August 27, 2005

Listing 42 illustrates an example of a user exit function written in VBScript.

Note Some parts of the following code snippet have been displayed in multiple lines only for better readability. These should be entered in a single line.

'//-----------------------------------------------------
'//
'//
'//  File:    ZTIUserExit.vbs
'//
'//  Function:    UserExit()
'//
'//  Input:    sType - user exit type (PHASE, SECTION)
'//        sWhen - when being called (BEFORE, AFTER)
'//        sDetail - detail for the exist (phase name, 
           section name)
'//        bSkip - flag to indicate whether to skip
           normal processing (only possible with BEFORE)
'// 
'//  Return:    Success - 0
'//             Failure - 1
'//
'//  Purpose:    This is a sample user exit, showing some
                 of the capabilities of a user exit.
'//        
'//-------------------------------------------------------
 
Function UserExit(sType, sWhen, sDetail, bSkip)
 
    Dim iRetVal
 
    LogInfo sLogFile, "User exit started: " & sType & "
    " & sWhen & " " & sDetail, LogTypeInfo
 
    If sType = "PHASE" and sDetail = "PREINSTALL" and 
    sWhen = "BEFORE" then
 
        ' Check to see if Windows PE is running from 
          a different drive than the first disk partition
        ' (as identified by OSD).  If this is the case,
          then this is a new machine and we can
        ' repartition and format the drive.
 
        If Left(objOSD("OSDTARGETDRIVE"), 2) <> 
          Left(wshEnv("SystemDrive"), 2) then
 
            ' First run DISKPART
 
            LogInfo sLogFile, "USEREXIT: About to run
            Diskpart.", LogTypeInfo
            iRetVal = wshShell.Run("DISKPART.EXE 
            /s """ & sThisScriptDir & "\ZTIDiskPart.txt""",
             0, true)
            If iRetVal <> Success then
                LogInfo sLogFile, 
                "USEREXIT: ERROR - Diskpart returned
                a non-zero return code, rc = " & iRetVal,
                LogTypeError
                UserExit = iRetVal
                EXIT FUNCTION
            End if
 
            ' Now run a quick format
 
            LogInfo sLogFile, "USEREXIT: About
            to run quick format.", LogTypeInfo
            iRetVal = wshShell.Run("FORMAT C: 
            /FS:NTFS /V:OSDisk /Q /Y", 0, true)
            If iRetVal <> Success then
                LogInfo sLogFile, 
"USEREXIT: ERROR - Quick format returned a non-zero 
return code, rc = " & iRetVal, LogTypeError
UserExit = iRetVal
                EXIT FUNCTION
            End if
        Else
            LogInfo sLogFile, "USEREXIT: Windows PE
is running from the system drive, must be a refresh.",
LogTypeInfo
        End if
    Else
        LogInfo sLogFile, "USEREXIT: No user exit
        processing is required.", LogTypeInfo
    End if
 
    UserExit = Success
 
End Function

Listing 42. User Exit function example in Visual Basic

Listing 43 illustrates a sample ZTIDiskPart.txt file used by ZTIUserExit.vbs to create the partitions. In Listing 42 you can see where the ZTIUserExit.vbs calls DiskPart.exe and passes ZTIDiskPart.txt as a parameter.

select disk 0
clean
create partition primary
assign letter=c:
active
exit 

Listing 43. ZTIDiskPart.txt parsed by ZTIUserExit.vbs

Both ZTIuserexit.vbs and ZTIDiskPart.txt must be included in the package that you are distributing to the workstation. For more information on updating OSD packages, see Microsoft Systems Management Server 2003 Operating System Deployment Feature Pack Users Guide in Additional Resources earlier in this guide.

Note   You need to include any user exit scripts in the OldComputer package source directory so that they can be accessed when it is time for the user exit script to be run.


Top of pageTop of pagePrevious17 of 25Next
**
In This Article
**