The location of all files are enumerated before any executions are done, which is also a plus, and if you're savvy with batch scripting (or writing any language), it shouldn't be difficult for you to just follow my pattern and utilize my functions in any manner you want.
Oh, and an intuitive log is written to: %SystemRoot%\Presetup.log
Update (09/26/2009)
Some major improvements were made. I'm not sure how well it will still work in an RIS setting. Hopefully there are no problems there. Changes include performance of my "FindFile" function so it should hopefully find your files a bit better. The log file now follows the same format as RogueSpear's ScriptPack.log.
There is also a new debug mode. The debug mode will do a few things for you. It will process presetup.cmd and write every line of code to presetup-debug.log. After processing presetup.cmd, it will halt windows installation process and pop up two windows so that you can review the presetup.log and the presetup-debug.log files. Once those windows are closed, windows setup will continue as usual. To activate debug mode, leave your copy of presetup.cmd in your i386 folder or where-ever you normally execute it from, and add another copy of presetup.cmd to your OEM directory (not $OEM$). Yes, they are the exact same file located in two different places. To deactivate debug mode, simply remove the presetup.cmd file from the OEM directory.
Update (06/06/2010)
A couple of minor tweaks were made to the debugging mode. I also found a bug in FindFile that has been fixed. If you're using a version that modifies mine and not having any problems, I wouldn't even bother updating your script to reflect my changes.
- Code: Select all
@Echo Off
@Prompt ----$G
@Echo.
@Set TAG=\WIN51
@For %%i In (C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do If Exist "%%i:%TAG%" Set CdDrive=%%i:
@If NOT DEFINED CdDrive Set CdDrive=%SystemDrive%
@Set OemDir=%CdDrive%\OEM
@If NOT Exist "%OemDir%" Set OemDir=%SystemDrive%
@Set LogFile="%SystemDrive%\Presetup.log"
@Call :FindFile "Presetup.cmd" "debug" "%OemDir%"
If Defined debug (
If Not [%~0]==[%debug%] (
@Call :WriteLine Begin
@Call :WriteLine [DEBUG] Found debug file [%debug%]
"%debug%">>"%SystemDrive%\Presetup-debug.log"
Exit
)
@Echo On
) Else @Call :WriteLine Begin
@Call :FindFile "7z.exe" "s7z"
@Call :FindFile "7za.exe" "s7za"
@Call :FindFile "un7zip.exe" "un7zip"
@Call :FindFile "DPsFnshr.ini" "DPsFnshr"
@Call :FindFile "DPsFnshr.7z" "DPsFnshr7z"
@Call :FindFile "DP*.7z" "DP"
@Call :FindFile "bin\*.7z" "bin7z"
@Call :FindFile "000_SR*.7z" "SR"
@Call :FindFile "000_SD*.7z" "SD"
@Call :FindFile "*.ins" "ins"
If DEFINED s7z @Call :CopyFile "%s7z%" "%SystemRoot%\"
If DEFINED s7za @Call :CopyFile "%s7za%" "%SystemRoot%\"
If DEFINED DPsFnshr @Call :CopyFile "%DPsFnshr%" "%SystemDrive%\"
If DEFINED ins @Call :CopyFile "%ins%" "%SystemDrive%\"
If DEFINED DPsFnshr7z @Call :unZip "%DPsFnshr7z%" "%SystemDrive%\"
If DEFINED bin7z @Call :unZip "%bin7z%" "%SystemDrive%\"
If DEFINED SR @Call :unZip "%SR%" "%SystemRoot%\"
If DEFINED SD @Call :unZip "%SD%" "%SystemDrive%\"
If DEFINED DP @Call :unZip "%DP%" "%SystemDrive%\"
If Exist %SystemDrive%\DP*.7z @Call :Delete "%SystemDrive%\DP*.7z"
If Exist %SystemDrive%\000*.7z @Call :Delete "%SystemDrive%\000*.7z"
If Exist %SystemDrive%\ch*.txt @Call :Delete "%SystemDrive%\ch*.txt"
@Call :FindFile "DevPath.exe" "SDP"
@Call :FindFile "DSPdsblr.exe" "WDSP"
@Call :FindFile "D\" "DPDIR"
If Defined debug (
@Call :WriteLine [DEBUG] ***
@Call :WriteLine [DEBUG] s7z=%s7z%
@Call :WriteLine [DEBUG] un7zip=%un7zip%
@Call :WriteLine [DEBUG] DPsFnshr=%DPsFnshr%
@Call :WriteLine [DEBUG] DPsFnshr7z=%DPsFnshr7z%
@Call :WriteLine [DEBUG] DP=%DP%
@Call :WriteLine [DEBUG] bin7z=%bin7z%
@Call :WriteLine [DEBUG] SR=%SR%
@Call :WriteLine [DEBUG] SD=%SD%
@Call :WriteLine [DEBUG] ins=%ins%
@Call :WriteLine [DEBUG] SDP=%SDP%
@Call :WriteLine [DEBUG] WDSP=%WDSP%
@Call :WriteLine [DEBUG] DPDIR=%DPDIR%
@Call :WriteLine [DEBUG] ***
)
If NOT DEFINED DPDIR (
@Call :WriteLine DriverPacks directory not found. Exiting...
@Goto Close
Exit
)
If NOT DEFINED WDSP (
@Call :WriteLine DriverPacks disabler not found. Exiting...
@Goto Close
Exit
)
If DEFINED SDP @Call :WriteLine [Command] "%SDP%" "%DPDIR%"
If DEFINED SDP "%SDP%" "%DPDIR%"
@Call :WriteLine [Command] Start "" "%WDSP%"
@Start "" "%WDSP%"
@Goto Close
@Goto :EOF
@Exit
:Delete
@Call :WriteLine [Delete] %~1
@Del /F %~1
@Goto :EOF
:unZip %1 %2
If DEFINED s7z Set unZip="%s7z%" x -y -aoa "%~1" -o"%~2"
If DEFINED s7za Set unZip="%s7za%" x -y -aoa "%~1" -o"%~2"
If DEFINED un7zip Set unZip=Start /wait /realtime /separate "" "%un7zip%" "%~1" "%~2"
@Call :WriteLine [unZip] ^<%~1^> to ^<%~2^>
If Not Exist "%~2" (
@Call :WriteLine [unZip] Invalid destination!
Goto :EOF
)
If Not Exist "%~1" (
@Call :WriteLine [unZip] Invalid source!
Goto :EOF
)
If Defined debug @Call :WriteLine [DEBUG] [unZip] %unZip%
%unZip%
If Not ErrorLevel 0 @Call :WriteLine [unZip] Error during extraction!
Goto :EOF
:CopyFile %1 %2
@Call :WriteLine [CopyFile] ^<%~1^> to ^<%~2^>
If Exist "%~1" Copy /V /Y "%~1" "%~2\" 1>Nul
If NOT Exist "%~2\%~nx1" @Call :WriteLine [CopyFile] File did not copy!
Goto :EOF
:FindFile %1 %2 %3
@REM * Call :FindFile "searchTerm" "OutputVariable"
@REM * Note: "searchTerm" may contain wildcards.
@Echo ----------------------------- FINDFILE BEGIN -----------------------------------------------
@Set NotFound=
If [%3]==[] (
@Call :FindFile %1 %2 "%OemDir%"
If DEFINED %~2 Goto :EOF
@Call :FindFile %1 %2 "%OemDir%\bin"
If DEFINED %~2 Goto :EOF
@Call :FindFile %1 %2 "%CdDrive%"
If DEFINED %~2 Goto :EOF
@Call :FindFile %1 %2 "%SystemDrive%"
If DEFINED %~2 Goto :EOF
@Set NotFound=1
@Call :WriteLine [FindFile] File/Folder not found {%~1}
@Goto :EOF
)
@REM * If Not [debug]==[%~2] @Call :WriteLine [FindFile] [%~1] in [%~3]
Pushd %3
If Exist "%~3\%~1" Set %~2=%~3\%~1
@For /F "tokens=1 delims=" %%A In ('Dir /a-d /b /s "%~1" 2^>nul ^| FIND /C /V ""') Do @Set Num=%%A
Set fType=unknown
If %Num% EQU 1 (Set fType=findFile)
If %Num% GTR 1 (Set fType=findDir)
If %Num% EQU 0 (
@For /F "tokens=1 delims= " %%A In ('Dir /ad /s "%~1" 2^>nul ^| Find "Dir(s)"') Do (
If %%A GTR 1 (Set fType=dir)
)
)
If [%fType%]==[findFile] (
@For /R "%CD%" %%A In (%~1) Do (
If Exist "%%~A" Set %~2=%%~A
If Exist "%%~A" Set f%~2=%%~A
)
)
@Echo %1 | FindStr /L /I /C:"*" >Nul
If %ErrorLevel% EQU 0 (
If %Num% EQU 1 (
Popd
@Goto :EOF
)
Set fType=findDir
)
If [%fType%]==[findDir] (
If Exist "%~3\%~1" (
Set %~2=%~3\%~1
Popd
@Goto :EOF
)
@For /R "%CD%" %%A In (%~1) Do (
If Exist "%%~dpA\%~1" Set %~2=%%~dpA
@Echo %1 | FindStr /L /I /C:"*" >Nul
If %ErrorLevel% EQU 0 Set %~2=%%~dpA\%~1
)
)
If [%fType%]==[dir] (
@Set %~2=%CD%\%~1
)
Popd
Goto :EOF
:TimeStamp
@REM * Create the date and time elements.
@Echo Off
@For /f "tokens=1-7 delims=.:/-, " %%i In ('Echo exit^|cmd /q /k"prompt $D $T"') Do (
@For /f "tokens=2-4 delims=/-,() skip=1" %%a In ('Echo.^|date') Do (
@Set dow=%%i
@Set %%a=%%j
@Set %%b=%%k
@Set %%c=%%l
@Set hh=%%m
@Set min=%%n
@Set ss=%%o
)
)
@Set TimeStamp=%yy%%mm%%dd%%hh%%min%%ss%
@If Defined debug @Echo On
@Goto :EOF
:WriteLine
@Call :TimeStamp
@If [%1]==[] @Goto :EOF
@Echo %*
@Echo %mm%/%dd%/%yy% %hh%:%mm%:%ss% - %~nx0 : %* >>"%LogFile%"
@Goto :EOF
:Close
If Defined debug (
If Not [%~0]==[%debug%] Call :WriteLine [DEBUG] Exiting debug mode...
If [%~0]==[%debug%] (
Echo
@REM Start "Review Debug File" /max /separate """%comspec%""" "/k "Type ""%SystemDrive%\Presetup-debug.log"" ^&Pause"
@REM Start "Review Log File" /max /separate /wait """%comspec%""" "/c "Type ""%LogFile%"" ^&Pause"
Start "" /max /separate "%SystemRoot%\Notepad.exe" "%LogFile%"
)
)
@Call :WriteLine End
Exit
@Goto :EOF

