Jump to content
Sign in to follow this  

File extension searching help

Recommended Posts

Hi Guys,

I've been working on a script to use on a WinPE boot disk that allows a user to automatically re-image their machine. I'm trying to make it work with different imaging programs, depending on what file extension is detected in the image source folder.

I've come up with something (I must admit, mainly from bits of script copied from elsewhere) that sort of works, but I'm a bit stuck on how to make it do what I really want.

What I really want it to do is to search a given folder (doesn't need to recurse) for files with certain extensions (either .WIM, .SWM, .GHO or .IMG) and then to use the correct imaging command line to put the image on the C:\ drive, depending on which of the extensions are found. If none of the extensions are detected, then a message should be shown to that effect and likewise if more than one of the extensions is found error out too.

Here is what I have so far, please could one of you gurus out there help me tweak it to work more like I need:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Comment=Auto Recovery Imaging using WinPE
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: v3.2.10.0
 Author:         Greg Nottage

 Script Function:
    Auto Recovery Imaging using WinPE
    Requires WinPE to have a \IX folder containing the image
    Designed for use with WinPE 2.0 or higher
    WinPE needs to have VBScript dlls registered
    Requires image files to be named img.xxx
    Requires confdsk.txt in %SYSTEMROOT%\System32 for diskpart
    Requires Ghost and Altiris apps in %PROGRAMFILES%
#ce ----------------------------------------------------------------------------

;Script Start

;Set AutoIt options
AutoItSetOption("TrayIconDebug", 1); Show debug info in tray icon
AutoItSetOption("WinTitleMatchMode", 2); 2 = Match any substring in title
AutoItSetOption("TrayIconHide", 1); 0 = do not hide, 1 = hide tray icon

;Set Variables
Global $fso = ObjCreate("Scripting.FileSystemObject")
$sEXT = "SWM"
$wEXT = "WIM"
$gEXT = "GHO"
$aEXT = "IMG"

;Main Script

;Ask if user wants to run, if not exit
   If msgbox(1, "*** WARNING ***", "Clicking OK will automatically re-image the C:\" & @CRLF &  "drive of your PC and wipe any existing data !!!" & @CRLF & @CRLF & "Click OK to re-image or Cancel to exit") = 2 then exit

; Detect which drive has the IMG folder
$DetDrv = _FindDrv('IX\img.WIM'); Detect which drive has the image folder
$SysDrv = EnvGet("SystemRoot"); Determine boot drive, i.e. X:
$oRootFolder = $fso.GetFolder($DetDrv & "\IX")

; Find the image files and use the correct image app

;RunWait(@ComSpec & " /c " & $SysDrv & '\System32\wpeutil reboot', "", @SW_HIDE); Restart

;Define Functions
Func _FindDrv($name)
   ;$drv = DriveGetDrive('CDROM'); For Boot from CD/DVD
   ;$drv = DriveGetDrive('REMOVABLE'); For Boot from USB
   $drv = DriveGetDrive('FIXED'); For testing (HDD)
   If Not @error Then
       For $i = 1 To $drv[0]
           If FileExists($drv[$i] & '\' & $name) Then Return $drv[$i]

Func _PrepDsk()
    RunWait(@ComSpec & " /c " & 'diskpart /s ' & $SysDrv & '\System32\confdsk.txt', "", @SW_HIDE)
    RunWait(@ComSpec & " /c " & 'FORMAT C: /FS:NTFS /V:SYSTEM /Q /Y', "", @SW_HIDE)
    RunWait(@ComSpec & " /c " & 'bootsect /nt52 c:', "", @SW_HIDE)

Func _ParseFiles($oFolder)
    $oFolders = $oFolder.SubFolders
    If $oFolders.Count Then
        For $oFolder in $oFolders
    $oFiles = $oFolder.Files
    For $oFile in $oFiles
        ;Msgbox(0, "Ext", $fso.GetExtensionName($oFile) & @CR)
        If $fso.GetExtensionName($oFile) = $sEXT Then ; Split WIM image
            Msgbox (0, "Split WIM Ext:", $fso.GetExtensionName($oFile) & @CR)
            ;_PrepDsk ; Prepare the disk ready for imaging
            ;RunWait(@ComSpec & " /c " & 'imagex /REF ' & $DetDrv & 'IX\img*.swm /apply ' & $DetDrv &'IX\img.SWM 1 C:\', "", @SW_SHOW)
        ElseIf $fso.GetExtensionName($oFile) = $wEXT Then ; Single WIM image
            Msgbox (0, "Full WIM Ext:", $fso.GetExtensionName($oFile) & @CR)
            ;_PrepDsk ; Prepare the disk ready for imaging
            ;RunWait(@ComSpec & " /c " & 'imagex /apply ' & $DetDrv & '\IX\img.WIM 1 C:\', "", @SW_SHOW)
        ElseIf $fso.GetExtensionName($oFile) = $gEXT Then ; Ghost image
            Msgbox (0, "Ghost Ext:", $fso.GetExtensionName($oFile) & @CR)
        ElseIf $fso.GetExtensionName($oFile) = $aEXT Then ; Altiris image
            Msgbox (0, "Altiris Ext:", $fso.GetExtensionName($oFile) & @CR)     

;Script End

Many thanks,


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...