/build/static/layout/Breadcrumb_cap_w.png

[Win PE] Imaging HDD Error Handler (SCCM)

School District (Win 7 x64 / Win 7 x86) Over 6000+ Clients
Network Environment: Active Directory + SCCM
---------------------------------------------------------------------------

Currently we are reworking our task sequences to run a bit more fluent and smooth. I was given the job of writing something that will give us a bit of redundancy in the event of errors or other "local" issues. The only real problems we've had in the past are errors that can be caused by corrupt partitions, files and/or folders. The problem with this is that partitioning within SCCM doesn't seem to have overwrite, override and noerr which are innate with DiskPart. Luckily for me, diskpart is built into Win PE and I took advantage of that with AutoIT.

Before I continue, I will let you know that I am typically a script kiddy. My script writing etiquette is disgusting and I recognize this so please bear with me and understand that I had to get all of this done in a couple of days so I was also in quite the hurry. This script will evolve including task sequence watching, etc... I would eventually like to include

- - The script was written with AutoIt - -
You will need to modify the diskprep.txt to fit your needs. In our clients, we have one hard drive and one partition in each machine. The only thing we need to do in this instance is format partition 1 on disk 0. The current setup overrides any files/folders being used on top of completing through errors (QUICK NOERR OVERRIDE). It then sets the partition to active and assigns it drive letter c. The txt file is easily modifiable as well as the primary script.

Below is the autoit script, if you would like to compile it but do not know how then visit the following link and install the autoit compiler. Paste the code in and compile - it's fairly simple and creates an executable at which you can call in your task sequence in a .cmd batch file. In my task sequence, after Win PE restarts, I call my batch file which is only one line: start TSMonitor.exe

After the script, I explain what it does and I tried to comment most of this script but it is not completely documented yet. I intend to release many different revisions allowing better portability to other systems and setups.

TSMonitor.au3

;Author: Timothy Wood
;Date: 07/01/11
#include <GUIConstantsEx.au3>
#include <String.au3>
HotKeySet("+!q", "Terminate") ;Shift+Alt+D
HotKeySet("+!d", "FormatPartition2") ;Shift+Alt+Q

;Begin the Loop
Global $Formatted=0
Global $WFlag=0
Global $timeupdate=1
Global $SM_POS_X=550
Global $SM_POS_Y=465
InitiateSeq() ;Initial variables for Time & More.
TSStatus()
WindowWatcher() ;Task Sequence Monitor Info Variables Here based on flags.
SplashTextOn("Task Sequence Monitor : " & $ADate, $TSM_Text & $ATimeStamp, 240, 100, $SM_POS_X, $SM_POS_Y, 2, "Times New Roman")

;Loop Statement
While 1
InitiateSeq() ;Start the veriable definitions.
WindowWatcher()
TSStatus()
;If $timeupdate=1 Then
ControlSetText("Task Sequence Monitor : " & $ADate, "", "[CLASS:Static; INSTANCE:1]", $TSM_Text & $ATimeStamp, 1) ;Update Splash Box
;EndIf
WEnd
;End of Loop Statement



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This function holds window reader functions to watch for errors;
Func WindowWatcher()
If WinExists("Task Sequence Wizard", "Welcome to the Task") Then
Global $WFlag=1 ;Welcomeing screen.
Global $IStatus=" Waiting..."
ElseIf WinExists("Task Sequence Wizard", "Select a task") Then
Global $WFlag=2 ;Select a task sequence window.
Global $IStatus=" [Select Image]"
ElseIf WinExists("Task Sequence Wizard", "Downloading policy") Then
Global $WFlag=3 ;Downloading policy
Global $IStatus=" Imaging System..."
ElseIf WinExists("Task Sequence Wizard", "(0x80070032).") AND $Formatted=0 Then
Global $WFlag=4 ;Format Partition - Error: 0x80070032
;Global $timeupdate=0 ;Stop Timer
Global $IStatus=" Failed. (Error: 0x80070032)"
FormatPartition()
;Write Ini Log
ElseIf WinExists("Task Sequence Error", "(0x8007081).") AND $Formatted=0 Then
Global $WFlag=5 ;Format Partition - Error: 0x8007081
;Global $timeupdate=0 ;Stop Timer
Global $IStatus=" Failed. (Error: 0x8007081)"
FormatPartition()
;Write Ini Log
ElseIf WinExists("Installation Progress", "") Then
Global $WFlag=3
Global $IStatus=" Installing..."
ElseIf $Formatted=1 Then
Global $WFlag=2
EndIf

sleep(100)
Global $TSM_Text = "Imaging Status:" & $IStatus ;IMG Status ($IStatus->Func TSStatus())
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This Function acts as a handler for $WFlag to update IMG Status & Popups
Func TSStatus()
If $WFlag=0 Then
Global $IStatus=" Initializing..."
Else
Return
EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Changes the status based upon WindowCatcher flags;;;;;;;;;;;;;;;
Func SplashInfo()
;Removed
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;Format Partition Function;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FormatPartition()
send("P") ;Hits the "Previous" button if it exists.
$EC1_MSGB = MsgBox(4100, "Task Sequence Monitor", "TS Monitor has detected an error in the partitioning task which can be the result of corrupt files, folders and/or partitions. Would you like to format the primary partition?")
Switch $EC1_MSGB
case 6 ;click yes
If $WFlag=4 Then
ControlSetText("Task Sequence Monitor : " & $ADate, "", "[CLASS:Static; INSTANCE:1]", "Imaging Status: Error Detected!", 1)
MsgBox(0,"Task Sequence Monitor","The system will now quickly format the active partition. If you wish to cancel this process, click the Exit box at the top right. Please keep in mind that clicking no will terminate the TS Monitoring service. This will NOT effect the system or the imaging process however it will disable error monitoring.")
RunWait("diskpart /s diskprep.txt")
Global $Formatted=1

MsgBox(0,"Task Sequence Monitor","The primary volume has been formatted! If you are unable to restart the imaging process - Restart PXE Boot and re-image system.")

ElseIf $WFlag=5 Then
ControlSetText("Task Sequence Monitor : " & $ADate, "", "[CLASS:Static; INSTANCE:1]", "Imaging Status: Error Detected!", 1)
MsgBox(0,"Task Sequence Monitor","The system will now quickly format the active partition. If you wish to cancel this process, click the Exit box at the top right. Please keep in mind that clicking no will terminate the TS Monitoring service. This will NOT effect the system or the imaging process however it will disable error monitoring.")
RunWait("diskpart /s diskprep.txt")
MsgBox(0,"Task Sequence Monitor","The primary volume has been formatted! If you are unable to restart the imaging process - Restart PXE Boot and re-image system.")
Global $Formatted=1
Exit 0
EndIf
case 7 ;click no
MsgBox(0, "Task Sequence Monitor", "TS Monitor can no longer provide support since you have chosen not to format. Terminating monitoring services until the imaging process has been restarted.")
Exit 0
EndSwitch
Global $WFlag=2
;MsgBox(0,"Test", "WFlag variable =" & $WFlag);Debugging purposes.
Return
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Format Partition Hotkey;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FormatPartition2()
$EC1_MSGB2 = MsgBox(4100, "Task Sequence Monitor", "Are you sure that you would like to format the primary active partition?")
Switch $EC1_MSGB2
case 6 ;click yes
RunWait("diskpart /s diskprep.txt")
MsgBox(0,"Task Sequence Monitor","The primary partition has been formatted and set to active!" & @LF & "TSM - C:\ - NTFS - Default - Active")
;Global $timeupdate=1
Return
case 7 ;click no
Return
EndSwitch
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This Function contains GVars for time updates;;;;;;;;;;;;;;;;;;;
Func InitiateSeq()
sleep(500)
;-Time Updating-;
If @HOUR > 12 AND $timeupdate=1 Then ;Format time for American Standard
Global $AHour = (@HOUR - 12) ;Conversion
Global $AMPM = "PM" ;AM - Decide if $AMPM = PM or not.
ElseIf @HOUR <= 12 AND $timeupdate=1 Then ;No Conversion
Global $AHour = @HOUR
Global $AMPM ="AM" ;PM - Decide if $AMPM = AM or not.
EndIf
;Time Conditions & If Statement EndFunc

;Define necessary global variables used in Time Stamp code
Global $ADate = @MON & "\" & @MDAY & "\" & @YEAR
Global $ASecond = @SEC ;Second Var
Global $AMinute = @MIN ;Minute Var
Global $ATimeStamp = @LF & $AHour & ":" & $AMinute & ":" & $ASecond & " " & $AMPM
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;Hotkey ALT+SHIFT+Q;;;;Function to Close Application;;;;;;;;;;
Func Terminate()
Exit 0
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



diskprep.txt

SELECT DISK 0
SELECT PARTITION 1
FORMAT FS=NTFS LABEL="Default" QUICK NOERR OVERRIDE
ACTIVE
ASSIGN LETTER=C



.:Instructions:.
  1. Compile the script in AutoIT
  2. In the same directory as the executable, place "diskprep.txt" containing the code above. Make modifications as you see fit. Keep diskprep.txt name the same, changing it will cause the script to fail.
  3. After Win PE starts, create a new task that will run a batch file. The batch file must contain the following:
    start theprogram.exe
  4. After that, you will see the dialogue window with the time (based off of bios time).


.:How it Works:.
When it first launches, it waits for specific windows to appear and it simply watches for specific errors (that I know of) that are a direct result of corrupt system files and folders. This can happen from machines being shutdown during the formatting/writing process as well as many other things.

When it first detects an error, it will either send you back to your task sequence selection or it will be at a point to where it cannot however it still will offer you an option to format the drive real quick - then you can reboot and imaging should work fine after that.

There are also hotkeys in place if you would like to pre-format before the imaging process. To accomplish this, when it is running - press ALT+SHIFT+D. You will be prompt with a msg box asking if you'd like to format the drive. If you click yes, it will perform this for you.

If you will to terminate the script and close it, you can then hit ALT+SHIFT+Q and it will exit the script.



That's all I have for now so if you're interested in contributing to my sloppy mess, I welcome criticism. I have many plans to extend this and yes - I do realize I could store all of these functions in external includes however I was pressed for time. I hope I can help someone else out there.

0 Comments   [ + ] Show comments

Answers (0)

Be the first to answer this question

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ