Presetup.cmd [20100606]

Releases, guides, changelogs, support and discussion of The ScriptPack. User created scripts and utilities.

Moderators: Waldo2k2, RogueSpear

Presetup.cmd [20100606]

Postby dumpydooby » Fri Jun 13, 2008 5:35 am

This is the Presetup.cmd file that I use on all of my discs. It functions similar to RogueSpear's in that it is compatible with his naming convention. The main difference is that mine has a lot of fail-safe features. This is especially recommended for use with multiboot discs or install-from-USB setups. The script will use 7z.exe or un7zip.exe, depending on which one is found (un7zip preferred). If 7z.exe is found, it will copy it over to the System32 directory as well (RogueSpear does this too).

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
Last edited by dumpydooby on Sun Jun 06, 2010 11:24 am, edited 6 times in total.
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm

Re: custom Presetup.cmd

Postby RogueSpear » Fri Jun 13, 2008 7:40 am

Holy batch file, man this is sweet. I especially like the logging function and the fact that the log will be included in the 7z archive created by the cleanup script in the ScriptPack. I'm going to play around with this one.
User avatar
RogueSpear
Site Admin
 
Posts: 1889
Joined: Mon Jun 26, 2006 1:14 pm
Location: Buffalo, NY

Re: custom Presetup.cmd

Postby dumpydooby » Mon Jun 16, 2008 8:22 pm

Yeah, I made sure it was *.log for that very reason. :)
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm

Re: custom Presetup.cmd

Postby msdemich » Mon Jul 21, 2008 4:44 pm

At the end of your :Presetup routine, what is that lonely "SET" command for?
msdemich
 
Posts: 25
Joined: Wed Apr 18, 2007 2:55 am

Re: custom Presetup.cmd

Postby dumpydooby » Thu Jul 24, 2008 8:16 pm

That's for debugging purposes. The output is dumped into the log file. So if you're having an issue with presetup, you can look through there to see if all of the files were properly found and check to see if the variables are properly set.
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm

Re: custom Presetup.cmd

Postby RogueSpear » Sun Sep 14, 2008 4:19 pm

I had to make some slight alterations to this in order to get it to work properly with RIS installs.
Code: Select all
    @Echo Off
    Echo.
    If Exist "%systemroot%\system32\setupold.exe" Del /F "%systemroot%\system32\setupold.exe"
    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%
    Call :Presetup>"%SystemRoot%\presetup.log"
    If NOT DEFINED DPDIR Goto :EOF
    If NOT DEFINED WDSP Goto :EOF
    "%SDP%" "%DPDIR%"
    Start "" %WDSP%
    Goto :EOF
    Exit

    :Presetup
    @Call :FindFile "7z.exe" "s7z"
    @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%\system32\"
    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%\"
    @Call :FindFile "DevPath.exe" "SDP"
    If Exist "%SystemDrive%\DSPdsblr.exe" Set WDSP=%SystemDrive%\DSPdsblr.exe
    If NOT DEFINED WDSP If Exist "%SystemDrive%\WatchDSP.exe" Set WDSP=%SystemDrive%\WatchDSP.exe
    @Call :FindFile "WatchDSP.exe" "WDSP"
    @Call :FindFile "DSPdsblr.exe" "WDSP"
    @Call :FindFile "D\*" "DPDIR"
    Set
    Goto :EOF

    :unZip %1 %2
    If DEFINED s7z Set unZip="%s7z%" x -y -aoa %1 -o%2
    If DEFINED un7zip Set unZip="%un7zip%" %1 %2
    @Echo Unzipping %1 to %2
    If Exist %2 If Exist %1 %unZip%
    If %ErrorLevel% GTR 0 @Echo: ...Could not extract!
    Goto :EOF

    :CopyFile %1 %2
    If Exist %1 Copy /V /Y %1 "%~2\" 1>Nul
    If NOT Exist "%~2\%~nx1" @Echo: ...File did not copy!
    Goto :EOF

    :FindFile %1 %2 %3
    @REM * Call :FindFile "searchTerm" "OutputVariable"
    @REM * Note: "searchTerm" may contain wildcards.
    If [%3]==[] (
       Echo Searching for ^<%~1^>
       @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
       @Echo: ...File not found!
       Goto :EOF
    )
    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)
       )
    )
    Echo %1 | FindStr /L /I /C:"*" >Nul
    If %ErrorLevel% EQU 0 Set fType=findDir
    If [%fType%]==[findDir] (
       If Exist "%~3\%~1" (
          Set %~2=%~3\%~1
          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%]==[findFile] (
       For /R "%CD%" %%A In (%~1) Do (
          If Exist "%%~A" Set %~2=%%~A
       )
    )
    If [%fType%]==[dir] (
       Set %~2=%CD%\%~1
    )
    Popd
    Goto :EOF


Changes are as follows:

  • Changed the line:
    Code: Select all
    If NOT DEFINED CdDrive Set CdDrive=%CD%\..\
    to:
    Code: Select all
    If NOT DEFINED CdDrive Set CdDrive=%systemdrive%

  • Changed the line:
    Code: Select all
    If NOT Exist "%OemDir%" FindFile "\OEM" OemDir "%CdDrive%"
    to:
    Code: Select all
    If NOT Exist "%OemDir%" Set OemDir=%systemdrive%

  • Removed the following two lines:
    Code: Select all
    @Call :FindFile %1 %2 "%SystemDrive%"
    If DEFINED %~2 Goto :EOF
User avatar
RogueSpear
Site Admin
 
Posts: 1889
Joined: Mon Jun 26, 2006 1:14 pm
Location: Buffalo, NY

Re: custom Presetup.cmd

Postby dumpydooby » Thu Aug 27, 2009 6:24 pm

20090827 - Updated it.

I noticed a MAJOR problem with un7zip failing. The reason was because I was tossing in an extra trailing slash, so un7zip was trying to extract to "C:\\" or something similar, and that would cause it to fail. Apparently the failure only occurred if it was for a drive letter. In any event, it should all be working now. I also made it so that the un7zip log is slightly more meaningful.


I don't think I implemented the changes you mentioned above. If I did, it was a long time ago. The one in my first post is the most recent one that I'm personally using. Feel free to use it and change it however you like.
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm

Re: custom Presetup.cmd

Postby dumpydooby » Fri Sep 25, 2009 11:49 am

20090925 - More updates made.

It now includes a prettier log file, an optional debug mode, and it should be more efficient at finding the files it needs.
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm

Re: Presetup.cmd [20100606]

Postby dumpydooby » Sun Jun 06, 2010 11:25 am

20100606 - A few minor updates.
Love Always,
Dumpy Dooby
User avatar
dumpydooby
 
Posts: 280
Joined: Fri Sep 01, 2006 8:22 pm


Return to Scripts and Utilities

Who is online

Users browsing this forum: No registered users and 1 guest

cron