Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
7.2 KiB

  1. @echo off
  2. REM
  3. REM Builds WinPE images from a professional
  4. REM distribution CD or from .Net server (ADS, Blade, Srv)
  5. REM
  6. REM
  7. REM Set required variables
  8. REM
  9. set X86PLATEXT=I386
  10. set IA64PLATEXT=IA64
  11. set PLATEXT=%X86PLATEXT%
  12. set SRCDIR=%1
  13. set DESTDIR=%2
  14. set SHOWUSG=no
  15. set IMAGENAME=
  16. set CREATEIMG=no
  17. set TAGPREFIX=win
  18. set ETFSBOOTSEC=etfsboot.com
  19. set SKIPWINSXS=yes
  20. set VERSION_CHECK=yes
  21. if "%SRCDIR%" == "" (
  22. set SHOWUSG=yes
  23. ) else if "%DESTDIR%" == "" (
  24. set SHOWUSG=yes
  25. ) else if "%SRCDIR%" == "/?" (
  26. set SHOWUSG=yes
  27. )
  28. if /i "%SHOWUSG%" == "yes" (
  29. goto :showusage
  30. )
  31. REM
  32. REM Parse the remaining optional arguments
  33. REM
  34. shift
  35. :parseargument
  36. shift
  37. set CURRENTARG=%1
  38. if "%CURRENTARG%" == "" (
  39. goto :donewithargs
  40. )
  41. if /i "%CURRENTARG%" == "/nosxs" (
  42. set SKIPWINSXS=yes
  43. goto :parseargument
  44. ) else if /i "%CURRENTARG%" == "/nover" (
  45. set VERSION_CHECK=no
  46. goto :parseargument
  47. ) else (
  48. set IMAGENAME=%CURRENTARG%
  49. set CREATEIMG=yes
  50. )
  51. :donewithargs
  52. REM
  53. REM echo SRCDIR=%SRCDIR%
  54. REM echo DESTDIR=%DESTDIR%
  55. REM echo SKIPWINSXS=%SKIPWINSXS%
  56. REM echo VERSION_CHECK=%VERSION_CHECK%
  57. REM echo IMAGENAME=%IMAGENAME%
  58. REM echo CREATEIMG=%CREATEIMG%
  59. REM
  60. REM
  61. REM Validate source directory
  62. REM
  63. if not EXIST %SRCDIR% (
  64. goto :showusage
  65. )
  66. set X86DIR=%SRCDIR%\I386
  67. set IA64DIR=%SRCDIR%\IA64
  68. if exist %IA64DIR% (
  69. set PLATEXT=IA64
  70. ) else if not exist %X86DIR% (
  71. goto :showusage
  72. )
  73. set WINPEOPTDIR=%CD%
  74. set WINPESRCDIR=%SRCDIR%\%PLATEXT%
  75. set WINPEDESTDIR=%DESTDIR%
  76. set OPTDIROK=yes
  77. set WINPEEXTRAFILE=%WINPEOPTDIR%\extra.inf
  78. if not exist %WINPEEXTRAFILE% (
  79. set OPTDIROK=no
  80. echo Cannot find %WINPEEXTRAFILE% file
  81. )
  82. if /i not "%OPTDIROK%" == "yes" (
  83. goto :missingoptdir
  84. )
  85. REM
  86. REM Change to optdir where we have the tools
  87. REM
  88. cd /d %WINPEOPTDIR%
  89. REM
  90. REM Make sure we have the correct version of the media
  91. REM
  92. if /i not "%VERSION_CHECK%" == "no" (
  93. echo Verifying media ...
  94. oemmint.exe /s:%SRCDIR% /#u:checkversion 2>1>nul
  95. if ERRORLEVEL 1 (
  96. echo.
  97. echo ERROR: Version mismatch, Please verify that you are using the
  98. echo correct version of Windows CD to create WinPE image.
  99. echo.
  100. goto :end
  101. )
  102. )
  103. REM
  104. REM Copy over the setupreg.hiv
  105. REM
  106. echo Building hives ...
  107. copy %WINPESRCDIR%\setupreg.hiv 2>1>nul
  108. if ERRORLEVEL 1 (
  109. echo Failed to copy setupreg.hiv file from CD
  110. goto :end
  111. )
  112. REM
  113. REM Copy over the required registry hive files
  114. REM
  115. copy %WINPESRCDIR%\hive*.inf 2>1>nul
  116. if ERRORLEVEL 1 (
  117. echo Failed to copy registry hive INF files
  118. goto :end
  119. )
  120. REM
  121. REM Copy over the intl.inf
  122. REM
  123. copy %WINPESRCDIR%\intl.inf 2>1>nul
  124. if ERRORLEVEL 1 (
  125. echo Failed to copy intl.inf
  126. goto :end
  127. )
  128. REM
  129. REM Copy over the font.inf
  130. REM
  131. if EXIST %WINPESRCDIR%\font.in_ (
  132. expand -r %WINPESRCDIR%\font.in_ %WINPEOPTDIR%\ 2>1>nul
  133. ) else (
  134. copy %WINPESRCDIR%\font.inf %WINPEOPTDIR%\ 2>1>nul
  135. )
  136. if ERRORLEVEL 1 (
  137. echo Failed to copy font.inf
  138. goto :end
  139. )
  140. REM
  141. REM Build the binary hives from INF files
  142. REM
  143. bldhives.exe .\config.inf 2>1>nul
  144. if ERRORLEVEL 1 (
  145. echo Failed to build hives from INF files
  146. goto :end
  147. )
  148. REM
  149. REM Start copying the required files
  150. REM
  151. echo Copying files ...
  152. rd %WINPEDESTDIR%\. /s /q 2>1>nul
  153. mkdir %WINPEDESTDIR%\%PLATEXT% 2>1>nul
  154. REM
  155. REM Copy the tag files from the root of the CD
  156. REM to the destination root first
  157. REM
  158. copy %SRCDIR%\%TAGPREFIX%* %WINPEDESTDIR% 2>1>nul
  159. REM
  160. REM Copy the bootfont.bin to root of the destination
  161. REM if one exists in i386 or IA64 directory
  162. REM
  163. if exist %SRCDIR%\%PLATEXT%\bootfont.bin (
  164. copy %SRCDIR%\%PLATEXT%\bootfont.bin %WINPEDESTDIR% 2>1>nul
  165. )
  166. REM
  167. REM Ok, now lets do the actual work
  168. REM echo srcdir=%SRCDIR% destdir=%winpedestdir% optdir=%winpeoptdir% extra=%winpeextrafile%
  169. REM
  170. oemmint.exe /v /s:%SRCDIR% /d:%WINPEDESTDIR%\%PLATEXT% /m:%WINPEOPTDIR% /e:%WINPEEXTRAFILE% 2>nul
  171. if ERRORLEVEL 1 (
  172. echo Failed to copy all the required files for WinPE
  173. ) else (
  174. echo Successfully created WinPE directory in %WINPEDESTDIR%
  175. )
  176. REM
  177. REM Copy the WinSxS directory also (for the time being)
  178. REM
  179. set WINSXSDIR=%WINDIR%\WinSxS
  180. if /i "%SKIPWINSXS%" == "no" (
  181. if exist %WINSXSDIR% (
  182. echo Copying WinSxS files ...
  183. mkdir %WINPEDESTDIR%\%PLATEXT%\WinSxS 2>1>nul
  184. xcopy %WINSXSDIR% %WINPEDESTDIR%\%PLATEXT%\WinSxS /s /e /h 2>1>nul
  185. if ERRORLEVEL 1 (
  186. echo Error in copying WinSxS directory to %WINPEDESTDIR%
  187. rd %WINPEDESTDIR%\%PLATEXT%\WinSxS /s /q 2>1>nul
  188. ) else (
  189. echo Successfully copied WinSxS directory to %WINPEDESTDIR%
  190. )
  191. attrib -s -h -r %WINPEDESTDIR%\%PLATEXT%\WinSxS
  192. attrib -s -h -r %WINPEDESTDIR%\%PLATEXT%\WinSxS\* /s
  193. ) else (
  194. echo Error in copying WinSxS directory to %WINPEDESTDIR%
  195. )
  196. )
  197. REM
  198. REM Copy some more required files
  199. REM
  200. copy %WINPEDESTDIR%\%PLATEXT%\winbom.ini %WINPEDESTDIR% 2>1>nul
  201. REM
  202. REM Check if we need to create a image
  203. REM
  204. if /i "%CREATEIMG%" == "no" (
  205. goto :end
  206. )
  207. echo Creating WinPE CD image ...
  208. REM
  209. REM Image the created install also
  210. REM
  211. set CDIMG_OPTS=-n
  212. if "%PLATEXT%" == "%X86PLATEXT%" (
  213. REM
  214. REM On X86 we need to user eftsboot.com
  215. REM
  216. set CDIMG_OPTS=%CDIMG_OPTS% -b%ETFSBOOTSEC%
  217. ) else (
  218. REM
  219. REM On ia64 we need to copy setupldr.efi to floppy
  220. REM and image it and user that as the boot image
  221. REM
  222. echo Copying setupldr.efi to A:\ ...
  223. copy %WINPEDESTDIR%\%PLATEXT%\setupldr.efi a:\ 2>1>nul
  224. if ERRORLEVEL 1 (
  225. echo Failed to copy setupldr.efi to floppy drive to create boot image
  226. goto :end
  227. )
  228. REM
  229. REM Image the floppy containing setupldr.efi
  230. REM
  231. echo Creating image of the floppy drive A:\ ...
  232. dskimage.exe a: efisys.bin 2>1>nul
  233. if not EXIST efisys.bin (
  234. echo Failed to image the floppy containing setupldr.efi for boot image.
  235. goto :end
  236. )
  237. set CDIMG_OPTS=%CDIMG_OPTS% -befisys.bin
  238. )
  239. REM
  240. REM Create the ISO image file now
  241. REM
  242. REM oscdimg.exe %CDIMG_OPTS% %WINPEDESTDIR% %IMAGENAME%
  243. REM
  244. echo Creating %IMAGENAME% image ...
  245. oscdimg.exe %CDIMG_OPTS% %WINPEDESTDIR% %IMAGENAME% 2>1>nul
  246. if ERRORLEVEL 1 (
  247. echo Failed to create the WinPE image in %IMAGENAME%
  248. goto :end
  249. ) else (
  250. echo Successfully created WinPE image in %IMAGENAME%
  251. )
  252. goto :end
  253. :missingoptdir
  254. echo Your current directory is not WinPE directory.
  255. echo Install the WinPE from OPK CD to a directory, then
  256. echo change to that directory and then execute this
  257. echo mkimg.cmd from that directory
  258. goto :end
  259. :showusage
  260. echo Usage: mkimg.cmd [/?] SourceDir DestinationDir [ImageName]
  261. echo.
  262. echo SourceDir : Drive letter to the Windows CD
  263. echo or network path to a share pointing to the root of
  264. echo the Windows CD.
  265. echo.
  266. echo DestinationDir : Path where the WinPE folder will be created
  267. echo before the CD image is created.
  268. echo.
  269. echo ImageName : Optional parameter, Specifies the file that
  270. echo will contain the WinPE ISO CD image.
  271. echo.
  272. echo.
  273. echo Example: mkimg.cmd F: c:\winpe c:\winpecd.img
  274. echo.
  275. echo In this example, F: is the drive letter that contains the Windows CD.
  276. echo This example creates a folder named C:\Winpe that contains the WINPE files. It also creates a file
  277. echo named C:\Winpecd.img that can be used to create a bootable WinPE CD.
  278. echo WinPE CD.
  279. echo.
  280. :end
  281. if /i not "%_NTPOSTBLD%" == "" (
  282. seterror.exe %errorlevel%
  283. )