1
1
@ setlocal DisableDelayedExpansion
2
- @ set uiv = v10.38
2
+ @ set uiv = v10.39
3
3
@ echo off
4
4
:: enable debug mode, you must also set target and repo (if updates are not beside the script)
5
5
set _Debug = 0
@@ -20,7 +20,7 @@ set "DismRoot=dism.exe"
20
20
:: enable .NET 3.5 feature
21
21
set Net35 = 1
22
22
23
- :: optional, specify custom "folder" path for microsoft-windows-netfx3-ondemand-package.cab
23
+ :: optional, custom "folder" path for microsoft-windows-netfx3-ondemand-package.cab
24
24
set " Net35Source = "
25
25
26
26
:: Cleanup OS images to "compress" superseded components (might take long time to complete)
@@ -56,6 +56,18 @@ set AutoStart=0
56
56
:: detect and use wimlib-imagex.exe for exporting wim files instead dism.exe
57
57
set UseWimlib = 0
58
58
59
+ :: ### Options for wim or distribution target only ###
60
+
61
+ :: add drivers to install.wim and boot.wim / winre.wim
62
+ set AddDrivers = 0
63
+
64
+ :: custom folder path for drivers - default is "Drivers" folder next to the script
65
+ :: the folder must contain subfolder for each drivers target:
66
+ :: ALL / drivers will be added to all wim files
67
+ :: OS / drivers will be added to install.wim only
68
+ :: WinPE / drivers will be added to boot.wim / winre.wim only
69
+ set " Drv_Source = \Drivers"
70
+
59
71
:: ### Options for distribution target only ###
60
72
61
73
:: convert install.wim to install.esd
@@ -67,7 +79,7 @@ set wim2esd=0
67
79
set wim2swm = 0
68
80
69
81
:: create new iso file
70
- :: require Win10 ADK, or place oscdimg.exe or cdimage.exe next to the script, or inside bin folder
82
+ :: require either of: Win10 ADK, oscdimg.exe, cdimage.exe, Windows Powershell
71
83
set ISO = 1
72
84
73
85
:: folder path for iso file, leave it blank to create ISO in the script current directory
235
247
isodir
236
248
delete_source
237
249
autostart
250
+ adddrivers
251
+ drv_source
238
252
) do (
239
253
call :ReadINI %% #
240
254
)
@@ -264,6 +278,8 @@ if "%UseWimlib%"=="" set UseWimlib=1
264
278
if " %ISO% " == " " set ISO = 1
265
279
if " %AutoStart% " == " " set AutoStart = 0
266
280
if " %Delete_Source% " == " " set Delete_Source = 0
281
+ if " %AddDrivers% " == " " set AddDrivers = 0
282
+ if " %Drv_Source% " == " " set " Drv_Source = \Drivers"
267
283
if " %wim2esd% " == " " set wim2esd = 0
268
284
if " %wim2swm% " == " " set wim2swm = 0
269
285
set _wlib = 0
@@ -276,6 +292,17 @@ if exist "wimlib-imagex.exe" set _wlib=1&set _wimlib="!_work!\wimlib-imagex.exe"
276
292
if exist " bin\wimlib-imagex.exe" set _wlib = 1& set _wimlib=" !_work! \bin\wimlib-imagex.exe"
277
293
if /i %xOS% == amd64 if exist " bin\bin64\wimlib-imagex.exe" set _wlib = 1& set _wimlib=" !_work! \bin\bin64\wimlib-imagex.exe"
278
294
)
295
+ if " !Drv_Source! " == " \Drivers" set " Drv_Source = !_work! \Drivers"
296
+ set " DrvSrcALL = "
297
+ set " DrvSrcOS = "
298
+ set " DrvSrcPE = "
299
+ if %AddDrivers% neq 0 if exist " !Drv_Source! \" (
300
+ cd /d " !Drv_Source! "
301
+ if exist ALL\ dir /b /s " ALL\*.inf" %_Nul3% && set " DrvSrcALL = !Drv_Source! \ALL"
302
+ if exist OS\ dir /b /s " OS\*.inf" %_Nul3% && set " DrvSrcOS = !Drv_Source! \OS"
303
+ if exist WinPE\ dir /b /s " WinPE\*.inf" %_Nul3% && set " DrvSrcPE = !Drv_Source! \WinPE"
304
+ cd /d " !_work! "
305
+ )
279
306
set _ADK = 0
280
307
set " showdism = Host OS"
281
308
set " _dism2 = %dismroot% /English /NoRestart /ScratchDir"
@@ -538,6 +565,9 @@ set "target=!_work!\DVD10UI"
538
565
)
539
566
call :extract
540
567
if %_sum% == 0 goto :fin
568
+ if %_build% geq 22000 (
569
+ if %LCUwinre% equ 2 (set LCUwinre=0) else (set LCUwinre=1)
570
+ )
541
571
542
572
:igonline
543
573
if %online% == 0 goto :igoffline
@@ -892,11 +922,15 @@ if %_extsafe%==1 (
892
922
%_exp% -f:*_microsoft-windows-sysreset_*.manifest " !repo! \!package! " " checker" %_Null%
893
923
if exist " checker\*_microsoft-windows-sysreset_*.manifest" findstr /i /m " Package_for_RollupFix" " checker\update.mum" %_Nul3% || set " _type = [SafeOS DU]"
894
924
)
895
- if %_extsafe% == 1 if not exist " checker\*_microsoft-windows-sysreset_*.manifest" (
925
+ if %_extsafe% == 1 if not defined _type (
926
+ %_exp% -f:*_microsoft-windows-winpe_tools_*.manifest " !repo! \!package! " " checker" %_Null%
927
+ if exist " checker\*_microsoft-windows-winpe_tools_*.manifest" findstr /i /m " Package_for_RollupFix" " checker\update.mum" %_Nul3% || set " _type = [SafeOS DU]"
928
+ )
929
+ if %_extsafe% == 1 if not defined _type (
896
930
%_exp% -f:*_microsoft-windows-winre-tools_*.manifest " !repo! \!package! " " checker" %_Null%
897
931
if exist " checker\*_microsoft-windows-winre-tools_*.manifest" findstr /i /m " Package_for_RollupFix" " checker\update.mum" %_Nul3% || set " _type = [SafeOS DU]"
898
932
)
899
- if %_extsafe% == 1 if not exist " checker\*_microsoft-windows-sysreset_*.manifest " (
933
+ if %_extsafe% == 1 if not defined _type (
900
934
%_exp% -f:*_microsoft-windows-i..dsetup-rejuvenation_*.manifest " !repo! \!package! " " checker" %_Null%
901
935
if exist " checker\*_microsoft-windows-i..dsetup-rejuvenation_*.manifest" findstr /i /m " Package_for_RollupFix" " checker\update.mum" %_Nul3% || set " _type = [SafeOS DU]"
902
936
)
@@ -1228,7 +1262,7 @@ set doboot=0
1228
1262
set doinstall = 0
1229
1263
if defined cumulative if exist " !mumtarget! \Windows\Servicing\Packages\*WinPE-LanguagePack*.mum" (
1230
1264
if %verb% == 0 if %LCUwinre% == 1 set dowinre = 1
1231
- if %verb% == 1 if %_build% neq 14393 set doboot = 1
1265
+ if %verb% == 1 set doboot = 1
1232
1266
)
1233
1267
if defined cumulative if not exist " !mumtarget! \Windows\Servicing\Packages\*WinPE-LanguagePack*.mum" (
1234
1268
if %verb% == 1 set doinstall = 1
@@ -1435,13 +1469,18 @@ if %verb%==1 (set /a _sum-=1&goto :eof)
1435
1469
set " safeos = !safeos! /PackagePath:%dest% \update.mum"
1436
1470
goto :eof
1437
1471
)
1438
- if exist " %dest% \*_microsoft-windows-winre-tools_*.manifest" if not exist " %dest% \*_microsoft-windows-sysreset_*.manifest" findstr /i /m " Package_for_RollupFix" " %dest% \update.mum" %_Nul3% || (
1472
+ if exist " %dest% \*_microsoft-windows-winpe_tools_*.manifest" if not exist " %dest% \*_microsoft-windows-sysreset_*.manifest" findstr /i /m " Package_for_RollupFix" " %dest% \update.mum" %_Nul3% || (
1473
+ if %verb% == 1 (set /a _sum-=1& goto :eof)
1474
+ set " safeos = !safeos! /PackagePath:%dest% \update.mum"
1475
+ goto :eof
1476
+ )
1477
+ if exist " %dest% \*_microsoft-windows-winre-tools_*.manifest" if not exist " %dest% \*_microsoft-windows-sysreset_*.manifest" if not exist " %dest% \*_microsoft-windows-winpe_tools_*.manifest" findstr /i /m " Package_for_RollupFix" " %dest% \update.mum" %_Nul3% || (
1439
1478
if not exist " !mumtarget! \Windows\Servicing\Packages\WinPE-SRT-Package~*.mum" (set /a _sum-=1& goto :eof)
1440
1479
if %verb% == 1 (set /a _sum-=1& goto :eof)
1441
1480
set " safeos = !safeos! /PackagePath:%dest% \update.mum"
1442
1481
goto :eof
1443
1482
)
1444
- if exist " %dest% \*_microsoft-windows-i..dsetup-rejuvenation_*.manifest" if not exist " %dest% \*_microsoft-windows-sysreset_*.manifest" if not exist " %dest% \*_microsoft-windows-winre-tools_*.manifest" findstr /i /m " Package_for_RollupFix" " %dest% \update.mum" %_Nul3% || (
1483
+ if exist " %dest% \*_microsoft-windows-i..dsetup-rejuvenation_*.manifest" if not exist " %dest% \*_microsoft-windows-sysreset_*.manifest" if not exist " %dest% \*_microsoft-windows-winpe_tools_*.manifest " if not exist " %dest% \*_microsoft-windows- winre-tools_*.manifest" findstr /i /m " Package_for_RollupFix" " %dest% \update.mum" %_Nul3% || (
1445
1484
if not exist " !mumtarget! \Windows\Servicing\Packages\WinPE-Rejuv-Package~*.mum" (set /a _sum-=1& goto :eof)
1446
1485
if %verb% == 1 (set /a _sum-=1& goto :eof)
1447
1486
set " safeos = !safeos! /PackagePath:%dest% \update.mum"
@@ -2036,6 +2075,7 @@ echo ============================================================
2036
2075
echo .
2037
2076
copy /y " !_work! \winre.wim" " !mountdir! \Windows\System32\Recovery\"
2038
2077
)
2078
+ if %AddDrivers% == 1 call :doDrv
2039
2079
echo .
2040
2080
echo ============================================================
2041
2081
echo Unmounting %_wimfile% - index %% #/%imgcount%
@@ -2216,6 +2256,7 @@ goto :eof
2216
2256
if %errorlevel% neq 0 goto :E_MOUNT
2217
2257
cd /d " !_cabdir! "
2218
2258
call :doupdate winre
2259
+ if %AddDrivers% == 1 call :reDrv
2219
2260
if !discardre! == 1 (
2220
2261
%_dism2% :" !_cabdir! " /Unmount-Wim /MountDir:" !winremount! " /Discard
2221
2262
if !errorlevel! neq 0 goto :E_MOUNT
@@ -2236,6 +2277,37 @@ goto :eof
2236
2277
set dismtarget = /image:" !mountdir! "
2237
2278
goto :eof
2238
2279
2280
+ :doDrv
2281
+ if exist " !mountdir! \Windows\Servicing\Packages\*WinPE-LanguagePack*.mum" (
2282
+ if not defined DrvSrcALL if not defined DrvSrcPE goto :eof
2283
+ ) else (
2284
+ if not defined DrvSrcALL if not defined DrvSrcOS goto :eof
2285
+ )
2286
+ echo .
2287
+ echo ============================================================
2288
+ echo Adding drivers...
2289
+ echo ============================================================
2290
+ if exist " !mountdir! \Windows\Servicing\Packages\*WinPE-LanguagePack*.mum" (
2291
+ if defined DrvSrcALL %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvWinPE.log" /Add-Driver /Driver:" !DrvSrcALL! " /Recurse
2292
+ if defined DrvSrcPE %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvWinPE.log" /Add-Driver /Driver:" !DrvSrcPE! " /Recurse
2293
+ ) else (
2294
+ if defined DrvSrcALL %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvOS.log" /Add-Driver /Driver:" !DrvSrcALL! " /Recurse
2295
+ if defined DrvSrcOS %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvOS.log" /Add-Driver /Driver:" !DrvSrcOS! " /Recurse
2296
+ )
2297
+ if !discard! == 1 (
2298
+ %_dism2% :" !_cabdir! " /Commit-Wim /MountDir:" !mountdir! "
2299
+ )
2300
+ goto :eof
2301
+
2302
+ :reDrv
2303
+ if not defined DrvSrcALL if not defined DrvSrcPE goto :eof
2304
+ if defined DrvSrcALL %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvWinRE.log" /Add-Driver /Driver:" !DrvSrcALL! " /Recurse
2305
+ if defined DrvSrcPE %_dism2% :" !_cabdir! " %dismtarget% /LogPath:" %_dLog% \DrvWinRE.log" /Add-Driver /Driver:" !DrvSrcPE! " /Recurse
2306
+ if !discardre! == 1 (
2307
+ %_dism2% :" !_cabdir! " /Commit-Wim /MountDir:" !winremount! "
2308
+ )
2309
+ goto :eof
2310
+
2239
2311
:cleanup
2240
2312
set savc = 0& set savr=1
2241
2313
if %_build% geq 18362 (set savc=3& set savr=3)
@@ -2940,11 +3012,9 @@ $DirectoryName = $CabFile.Substring(0, $CabFile.LastIndexOf('.'))
2940
3012
$PSFFile = $DirectoryName + " .psf"
2941
3013
$null = [IO.Directory]::CreateDirectory($DirectoryName)
2942
3014
$DeltaList = G $DirectoryName
2943
- $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
2944
- $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
2945
- $TypeBuilder = $ModuleBuilder.DefineType(0)
2946
- [void]$TypeBuilder.DefinePInvokeMethod('ApplyDeltaW', 'msdelta.dll', 'Public, Static', 1, [int], @ ([Int64], [String], [String], [String]), 1, 3)
2947
- $MSD = $TypeBuilder.CreateType()
3015
+ $TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
3016
+ [void]$TB.DefinePInvokeMethod('ApplyDeltaW', 'msdelta.dll', 'Public, Static', 1, [int], @ ([Int64], [String], [String], [String]), 1, 3)
3017
+ $MSD = $TB.CreateType()
2948
3018
$PSFFileStream = [IO.File]::OpenRead([IO.Path]::GetFullPath($PSFFile))
2949
3019
$cwd = [IO.Path]::GetFullPath($DirectoryName)
2950
3020
[Environment]::CurrentDirectory = $cwd
@@ -2979,15 +3049,23 @@ $null = [IO.Directory]::Delete("000", $True)
2979
3049
:wimmsu:
2980
3050
function E($WimPath, $InnFile, $OutFile) {
2981
3051
$DllPath = 'wimgapi.dll'
2982
- $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
2983
- $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
2984
- $TypeBuilder = $ModuleBuilder.DefineType(0)
2985
- [void]$TypeBuilder.DefinePInvokeMethod('WIMCreateFile', $DllPath, 'Public, Static', 1, [IntPtr], @ ([String], [UInt32], [Int32], [Int32], [Int32], [Int32].MakeByRefType()), 1, 3).SetImplementationFlags(128)
2986
- [void]$TypeBuilder.DefinePInvokeMethod('WIMLoadImage', $DllPath, 'Public, Static', 1, [IntPtr], @ ([IntPtr], [Int32]), 1, 3).SetImplementationFlags(128)
2987
- [void]$TypeBuilder.DefinePInvokeMethod('WIMSetTemporaryPath', $DllPath, 'Public, Static', 1, [int], @ ([IntPtr], [String]), 1, 3)
2988
- [void]$TypeBuilder.DefinePInvokeMethod('WIMExtractImagePath', $DllPath, 'Public, Static', 1, [int], @ ([IntPtr], [String], [String], [Int32]), 1, 3)
2989
- [void]$TypeBuilder.DefinePInvokeMethod('WIMCloseHandle', $DllPath, 'Public, Static', 1, [int], @ ([IntPtr]), 1, 3)
2990
- $WIMG = $TypeBuilder.CreateType()
3052
+ $TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
3053
+ $FN = @ (
3054
+ 'WIMCreateFile;IntPtr;String, UInt32, Int32, Int32, Int32, Int32#Ref;128',
3055
+ 'WIMLoadImage;IntPtr;IntPtr, Int32;128',
3056
+ 'WIMSetTemporaryPath;int;IntPtr, String;0',
3057
+ 'WIMExtractImagePath;int;IntPtr, String, String, Int32;0',
3058
+ 'WIMCloseHandle;int;IntPtr;0'
3059
+ )
3060
+ foreach ($str in $FN) {
3061
+ $m=$str -split ';'
3062
+ $r=$m[1] -as [Type]
3063
+ $f=$m[3] -as [int]
3064
+ $p = [Collections.ArrayList]@ ()
3065
+ $m[2] -split ', ' | % { $i = $_ -split '#'; if ($null -eq $i[1]) {$p += ($_ -as [type])} else {$p += (($i[0] -as [type]).MakeByRefType())} }
3066
+ [void]$TB.DefinePInvokeMethod($m[0], $DllPath, 22, 1, $r, $p, 1, 3).SetImplementationFlags($f)
3067
+ }
3068
+ $WIMG = $TB.CreateType()
2991
3069
$hWim = 0
2992
3070
$hImage = 0
2993
3071
$hWim = $WIMG::WIMCreateFile($WimPath, " 0x80000000" , 3, " 0x20000000" , 0, [ref]$null)
0 commit comments