-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlwaysUpdate.bat
More file actions
1576 lines (1422 loc) · 97.7 KB
/
Copy pathAlwaysUpdate.bat
File metadata and controls
1576 lines (1422 loc) · 97.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off & goto :init
:AlwaysUpdate v1.1 - Universal Windows Upgrade Tool
::===========================================================================
:: AlwaysUpdate v1.1 - Universal Windows Upgrade Tool
:: (c) 2026 Ayi NEDJIMI Consultants - https://ayinedjimi-consultants.fr
:: (c) 2026 Ayi NEDJIMI Consultants - Tous droits reserves
::
:: Upgrades ANY Windows 10/11 to latest Windows 11 bypassing ALL hw checks
:: Nothing but Microsoft-hosted source links - no third-party tools
::
:: Enhancements over original: pre-flight checks, logging, progress bar,
:: retry downloads, comprehensive hardware bypass,
:: 24H2/25H2 support, full-auto mode, polished UI
::
:: Changelog:
:: 2026.06.04 v1.1
:: - Full auto mode defaults to latest available version (currently 24H2)
:: - New catalog capture method: runs fwlink MCT briefly to obtain latest
:: products catalog from Microsoft, replacing unreliable binary extraction
:: - Download verification: reject 0-byte/incomplete downloads
:: - Evaluation edition detection with user warning
:: - Dynamic TargetReleaseVersionInfo in AutoUnattend.xml
:: - Improved logging throughout
::
:: 2026.03.28 v1.0 stable
:: - Initial release with all improvements
:: - Uses 23H2 MCT (last without built-in TPM check) + products catalog
:: - Comprehensive hardware bypass (TPM, SecureBoot, CPU, RAM, Storage)
:: - Real-time progress bar with status tracking
:: - Pre-flight system checks (disk, network, PS, processes)
:: - Detailed logging to %SystemDrive%\ESD\AlwaysUpdate.log
::===========================================================================
::# ======================== USER CONFIGURATION ========================
:config
::# Uncomment to skip GUI dialog - or rename script: "24H2 AlwaysUpdate.bat"
rem set MCT=2510
::# Uncomment to start auto upgrade directly (no prompts) to latest version
::# Or rename script: "auto AlwaysUpdate.bat"
rem set /a AUTO=1
::# Uncomment to start create iso directly - or rename: "iso 24H2 AlwaysUpdate.bat"
rem set /a ISO=1
::# Uncomment to change autodetected MediaEdition
rem set EDITION=Enterprise
::# Uncomment to change autodetected MediaLangCode
rem set LANGCODE=en-US
::# Uncomment to change autodetected MediaArch
rem set ARCH=x64
::# Uncomment to change autodetected KEY
rem set KEY=NPPR9-FWDCX-D2C8J-H872K-2YT43
::# Uncomment to disable dynamic update for setup sources
rem set /a NO_UPDATE=1
::# Uncomment to create default untouched MCT media (no bypass, no mods)
rem set /a DEF=1
::# Recommended setup options for upgrades
set OPTIONS=%OPTIONS% /Compat IgnoreWarning /MigrateDrivers All /ResizeRecoveryPartition Disable /ShowOOBE None
::# Disable telemetry and Compact OS
set OPTIONS=%OPTIONS% /Telemetry Disable /CompactOS Disable
::# Unhide Enterprise editions in products.xml
set /a UNHIDE_BUSINESS=1
::# Insert Enterprise esd links for older versions
set /a INSERT_BUSINESS=1
::# Version choice items and default [* 11_24H2]
set VERSIONS=11_23H2,* 11_24H2,11_25H2
set /a dV=2
::# Preset choice items and default [Manual select]
set PRESETS=^&Full Auto Upgrade,^&Auto Upgrade,Create ^&ISO,Create ^&USB,^&Manual Select,MCT ^&Default
::# 23H2 MCT is used for all versions (last MCT without built-in TPM check)
::# For 24H2/25H2: catalog is captured by running the fwlink MCT briefly, then 23H2 MCT uses it
set /a dP=5
::# ======================== END USER CONFIG ========================
:begin
call :reg_query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentBuildNumber" OS_VERSION
call :reg_query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" "DisplayVersion" OS_VID
call :reg_query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" "EditionID" OS_EDITION
call :reg_query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName" OS_PRODUCT
call :reg_query "HKU\S-1-5-18\Control Panel\Desktop\MuiCached" "MachinePreferredUILanguages" OS_LANGCODE
for %%s in (%OS_LANGCODE%) do set "OS_LANGCODE=%%s"
set "OS_ARCH=x64" & if "%PROCESSOR_ARCHITECTURE:~-2%" equ "86" if not defined PROCESSOR_ARCHITEW6432 set "OS_ARCH=x86"
::# Language detection (FR or EN based on OS language)
set "LANG=EN"
echo;%OS_LANGCODE% | find /i "fr-" >nul 2>nul && set "LANG=FR"
echo;[%date% %time%] OS: %OS_PRODUCT% %OS_VID% Build %OS_VERSION% %OS_EDITION% %OS_ARCH% [%LANG%] >> "%LOGFILE%" 2>nul
::# parse MCT choice from script name or commandline
for %%V in (1.2310 1.11_23H2 2.2409 2.11_24H2 3.2510 3.11_25H2) do for %%s in (%MCT% %~n0 %*) do if /i %%~xV equ .%%~s set "MCT=%%~nV" & set "VID=%%~s"
if defined MCT if not defined VID set "MCT="
::# parse AUTO from script name or commandline
for %%s in (%~n0 %*) do if /i %%s equ auto set /a AUTO=1
if defined AUTO (set /a PRE=2 & if not defined MCT set /a MCT=%dV%)
::# parse FULLAUTO from script name - Full Auto Upgrade preset
for %%s in (%~n0 %*) do if /i %%s equ fullauto set /a FULLAUTO=1
if defined FULLAUTO (set /a AUTO=1& set /a PRE=1& set /a MCT=%dV%)
::# parse ISO from script name or commandline
for %%s in (%~n0 %*) do if /i %%s equ iso set /a ISO=1
if defined ISO (set /a PRE=3 & if defined AUTO set "AUTO=")
::# parse EDITION from script name or commandline
set _=%EDITION% %~n0 %*& rem also accepts alternative names
for %%s in (%_:Home=Core% %_:Pro =Professional % %_:ProN=ProfessionalN% %_:Edu =Education % %_:EduN=EducationN%) do (
for %%E in ( ProfessionalEducation ProfessionalEducationN ProfessionalWorkstation ProfessionalWorkstationN Cloud CloudN
Core CoreN CoreSingleLanguage CoreCountrySpecific Professional ProfessionalN Education EducationN Enterprise EnterpriseN
) do if /i %%s equ %%E set "EDITION=%%E")
::# parse LANGCODE from script name or commandline
for %%s in (%~n0 %*) do set ".=%%~s" & for /f %%C in ('cmd /q /v:on /c echo;!.:~2^,1!') do if "%%C" equ "-" set "LANGCODE=%%s"
::# parse ARCH from script name or commandline
for %%s in (%~n0 %*) do for %%A in (x86 x64) do if /i %%s equ %%A set "ARCH=%%A"
::# parse KEY from script name or commandline
for %%s in (%KEY% %~n0 %*) do for /f "tokens=1-5 delims=-" %%A in ("%%s") do if "%%E" neq "" set "PKEY=%%s" & set "KEY="
if defined PKEY set "PKEY1=%PKEY:~-1%" & set "PKEY28=%PKEY:~28,1%"
if defined EDITION if "%PKEY1%" equ "%PKEY28%" (set "KEY=%PKEY%") else set "PKEY="
::# parse NO_UPDATE from script name or commandline
for %%s in (%~n0 %*) do if /i %%s equ no_update set "NO_UPDATE=1"
if defined NO_UPDATE (set OPTIONS=%OPTIONS% /DynamicUpdate Disable) else (set OPTIONS=%OPTIONS% /DynamicUpdate Enable)
::# parse DEF from script name or commandline
for %%s in (%~n0 %*) do if /i %%s equ def set "DEF=def"
::# hide option
set /a hide=2 & for %%s in (%~n0 %*) do if /i %%s equ hide set /a hide=1
::# auto detected / selected media preset
if defined EDITION (set MEDIA_EDITION=%EDITION%) else (set MEDIA_EDITION=%OS_EDITION%)
if defined LANGCODE (set MEDIA_LANGCODE=%LANGCODE%) else (set MEDIA_LANGCODE=%OS_LANGCODE%)
if defined ARCH (set MEDIA_ARCH=%ARCH%) else (set MEDIA_ARCH=%OS_ARCH%)
if not defined VID (set VID=%OS_VID%)
::# edition fallback to ones that MCT supports (IoTEnterpriseS before IoTEnterprise)
::# warn about Eval editions (licensing restrictions may prevent upgrade)
echo;%OS_EDITION% | find /i "Eval" >nul 2>nul && (
echo;[%date% %time%] WARN: Evaluation edition detected: %OS_EDITION% >> "%LOGFILE%" 2>nul
if "%LANG%"=="FR" (
%<%:4f " [AVIS] Edition Evaluation detectee: %OS_EDITION% "%>%
%<%:3f " La mise a niveau peut echouer ou produire une installation non activee "%>%
) else (
%<%:4f " [NOTE] Evaluation edition detected: %OS_EDITION% "%>%
%<%:3f " Upgrade may fail or produce an unlicensed installation "%>%
)
echo;
)
(set MEDIA_EDITION=%MEDIA_EDITION:Eval=%)
(set MEDIA_EDITION=%MEDIA_EDITION:Embedded=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:IoTEnterpriseS=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:IoTEnterprise=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:EnterpriseS=Enterprise%)
::# get previous GUI selection if self elevated
for %%s in (%*) do for %%P in (1 2 3 4 5 6) do if %%~ns gtr 0 if %%~ns lss 4 if %%~xs. equ .%%P. (set /a PRE=%%P & set /a MCT=%%~ns)
::# write auto media preset hint
%<%:f0 " Detected System "%>>% & if defined MCT %<%:5f " %VID% "%>>%
%<%:6f " %MEDIA_LANGCODE% "%>>% & %<%:9f " %MEDIA_EDITION% "%>>% & %<%:2f " %MEDIA_ARCH% "%>%
echo;
if "%LANG%"=="FR" (
%<%:1f " 1 Full Auto Mise a niveau vers la derniere version - SANS INTERACTION "%>%
%<%:1f " 2 Mise a niveau Upgrade assistee vers la version selectionnee "%>%
%<%:1f " 3 Creer ISO Telecharge et cree un fichier ISO dans C:\ESD "%>%
%<%:1f " 4 Creer USB Telecharge et cree une cle USB bootable "%>%
%<%:1f " 5 Selection manuelle Choix libre de l'edition, langue et architecture "%>%
%<%:1f " 6 MCT par defaut Lance le Media Creation Tool sans modification "%>%
echo;
%<%:17 " Bypass complet : TPM, SecureBoot, CPU, RAM, Stockage "%>%
%<%:17 " Renommer en "%>>% & %<%:1f "def AlwaysUpdate.bat"%>>% & %<%:17 " pour un media sans modification "%>%
) else (
%<%:1f " 1 Full Auto Upgrade to latest Windows 11 version - NO PROMPTS "%>%
%<%:1f " 2 Auto Upgrade Assisted upgrade to selected version "%>%
%<%:1f " 3 Create ISO Download and create ISO file in C:\ESD "%>%
%<%:1f " 4 Create USB Download and create bootable USB drive "%>%
%<%:1f " 5 Manual Select Choose edition, language and architecture "%>%
%<%:1f " 6 MCT Default Run Media Creation Tool without modifications "%>%
echo;
%<%:17 " Full hardware bypass: TPM, SecureBoot, CPU, RAM, Storage "%>%
%<%:17 " Rename to "%>>% & %<%:1f "def AlwaysUpdate.bat"%>>% & %<%:17 " to create unmodified media "%>%
)
::# show pseudo-menu dialog
if "%MCT%%PRE%"=="" call :choices2 MCT "%VERSIONS%" %dV% "AlwaysUpdate - Version" PRE "%PRESETS%" %dP% "AlwaysUpdate - Preset" 11 white 0x3d0000 320
if %MCT%0 lss 1 if %PRE%0 gtr 1 call :choices MCT "%VERSIONS%" %dV% "AlwaysUpdate - Version" 11 white 0x3d0000 320
if %MCT%0 gtr 1 if %PRE%0 lss 1 call :choices PRE "%PRESETS%" %dP% "AlwaysUpdate - Preset" 11 white 0x3d0000 320
if %MCT%0 gtr 1 if %PRE%0 lss 1 goto choice-0 = cancel
goto choice-%MCT%
::# ----------- VERSION DEFINITIONS (23H2, *24H2, 25H2) -----------
::# 23H2 MCT EXE is used for ALL versions (last MCT without built-in TPM check)
::# For 24H2/25H2: catalog captured by running fwlink MCT briefly, then 23H2 MCT uses it
:choice-3
set "VER=26200" & set "VID=11_25H2" & set "CB=26200.1000.250315-1200.25h2_release" & set "CT=2026/03/" & set "CC=2.0"
set "FWLINK_MCT=https://go.microsoft.com/fwlink/?linkid=2156295"
set "EXE=https://download.microsoft.com/download/e/c/d/ecd532eb-bed0-465a-9b7a-330066bec3ce/MediaCreationTool_Win11_23H2.exe"
goto process
:choice-2
set "VER=26100" & set "VID=11_24H2" & set "CB=26100.1742.240906-0331.24h2_release_svc_refresh" & set "CT=2025/10/" & set "CC=2.0"
set "FWLINK_MCT=https://go.microsoft.com/fwlink/?linkid=2156295"
set "EXE=https://download.microsoft.com/download/e/c/d/ecd532eb-bed0-465a-9b7a-330066bec3ce/MediaCreationTool_Win11_23H2.exe"
goto process
:choice-1
set "VER=22631" & set "VID=11_23H2" & set "CB=22631.2861.231204-0538.23H2_ni_release_svc_refresh" & set "CT=2023/12/" & set "CC=2.0"
set "CAB=https://download.microsoft.com/download/6/2/b/62b47bc5-1b28-4bfa-9422-e7a098d326d4/products_win11_20231208.cab"
set "EXE=https://download.microsoft.com/download/e/c/d/ecd532eb-bed0-465a-9b7a-330066bec3ce/MediaCreationTool_Win11_23H2.exe"
goto process
:choice-
set /a MCT=%dv% & set /a PRE=%dP% & goto choice-%dV%
:choice-0
%<%:0c " CANCELED "%>% & timeout /t 3 >nul & exit /b
::# ======================== CONSOLE INIT ========================
:init
@echo off& title AlwaysUpdate v1.1& set __COMPAT_LAYER=Installer& chcp 437 >nul& set set=& for %%s in (%*) do if /i %%s equ set (set set=1)
if not defined set set /a BackClr=0x1 & set /a TextClr=0xf & set /a Columns=32 & set /a Lines=120 & set /a Buff=9999
if not defined set set /a SColors=BackClr*16+TextClr & set /a WSize=Columns*256*256+Lines & set /a BSize=Buff*256*256+Lines
if not defined set for %%s in ("HKCU\Console\AlwaysUpdate") do (
reg add HKCU\Console /v ForceV2 /d 0x01 /t reg_dword /f & reg add %%s /v ScreenColors /d %SColors% /t reg_dword /f
reg add %%s /v ColorTable00 /d 0x000000 /t reg_dword /f & reg add %%s /v ColorTable08 /d 0x767676 /t reg_dword /f
reg add %%s /v ColorTable01 /d 0x00003d /t reg_dword /f & reg add %%s /v ColorTable09 /d 0x4444ff /t reg_dword /f
reg add %%s /v ColorTable02 /d 0x0066cc /t reg_dword /f & reg add %%s /v ColorTable10 /d 0x33aaff /t reg_dword /f
reg add %%s /v ColorTable03 /d 0x0088dd /t reg_dword /f & reg add %%s /v ColorTable11 /d 0x44ccff /t reg_dword /f
reg add %%s /v ColorTable04 /d 0x0000ee /t reg_dword /f & reg add %%s /v ColorTable12 /d 0x3333ff /t reg_dword /f
reg add %%s /v ColorTable05 /d 0x220088 /t reg_dword /f & reg add %%s /v ColorTable13 /d 0x4400cc /t reg_dword /f
reg add %%s /v ColorTable06 /d 0x3333cc /t reg_dword /f & reg add %%s /v ColorTable14 /d 0x9999ff /t reg_dword /f
reg add %%s /v ColorTable07 /d 0xcccccc /t reg_dword /f & reg add %%s /v ColorTable15 /d 0xffffff /t reg_dword /f
reg add %%s /v QuickEdit /d 0x0000 /t reg_dword /f & reg add %%s /v LineWrap /d 0 /t reg_dword /f
reg add %%s /v LineSelection /d 0x0001 /t reg_dword /f & reg add %%s /v CtrlKeyShortcutsDisabled /d 0 /t reg_dword /f
reg add %%s /v WindowSize /d %WSize% /t reg_dword /f & reg add %%s /v ScreenBufferSize /d %BSize% /t reg_dword /f
reg add %%s /v FontSize /d 0x00100008 /t reg_dword /f & reg add %%s /v FaceName /d "Consolas" /t reg_sz /f ) >nul 2>nul
pushd "%~dp0" & set "S=%SystemRoot%" & set "nx0=%~nx0" & call set "nx0=%%nx0:)=]%%" & call set "nx0=%%nx0:(=[%%"
set "PATH=%S%\Sysnative;%S%\Sysnative\windowspowershell\v1.0\;%S%\System32;%S%\System32\windowspowershell\v1.0\;%PATH%"
set "WORK=%SystemDrive%\ESD" & if not defined ROOT (set "ROOT=%CD%") else if not exist "%ROOT%\*.bat" set "ROOT=%CD%"
set "LOGFILE=%SystemDrive%\ESD\AlwaysUpdate.log"
mkdir "%WORK%" >nul 2>nul & attrib -R -S -H "%WORK%" >nul 2>nul & copy /y "%~f0" "%WORK%\%~nx0" >nul 2>nul
if "%~nx0" neq "%nx0%" copy /y "%WORK%\%~nx0" "%WORK%\%nx0%" >nul & del /f /q "%WORK%\%~nx0" >nul
if not exist "%WORK%\%nx0%" (echo;FATAL: Cannot copy script to %WORK% - check disk space or permissions & pause & exit /b 1)
if not defined set start "AlwaysUpdate" cmd /d /x /c set "ROOT=%ROOT%" ^& call "%WORK%\%nx0%" %* set& exit /b
::# display banner
prompt $G & echo;
echo; ================================================================
echo; ^| ^|
echo; ^| ##### # # # ##### # # #### ^|
echo; ^| # # # # # # # # # # ^|
echo; ^| ##### # # # # ##### # # #### ^|
echo; ^| # # # ## ## # # # # ^|
echo; ^| # # ##### # # # # # #### ^|
echo; ^| ^|
echo; ^| U P D A T E v 1 . 0 ^|
echo; ^| ^|
echo; ^| Universal Windows Upgrade Tool ^|
echo; ^| Full bypass: TPM, SecureBoot, CPU, RAM, Storage ^|
echo; ^| ^|
echo; ^| (c) 2026 Ayi NEDJIMI Consultants ^|
echo; ^| https://ayinedjimi-consultants.fr ^|
echo; ^| ^|
echo; ================================================================
echo;
::# lean xp+ color macros
for /f "delims=:" %%s in ('echo;prompt $h$s$h:^|cmd /d') do set "|=%%s"&set ">>=\..\c nul&set /p s=%%s%%s%%s%%s%%s%%s%%s<nul&popd"
set "<=pushd "%WORK%"&2>nul findstr /c:\ /a" &set ">=%>>%&echo;" &set "|=%|:~0,1%" &set /p s=\<nul>"%WORK%\c"
::# init log
echo;[%date% %time%] === AlwaysUpdate v1.1 Started === >> "%LOGFILE%" 2>nul
::# undefine main variables
for %%s in (OPTIONS MCT XML CAB EXE VID PRE AUTO FULLAUTO ISO EDITION KEY ARCH LANGCODE NO_UPDATE DEF AKEY FWLINK_MCT) do set "%%s="
for %%s in (latest_AlwaysUpdate.url) do if not exist %%s (echo;[InternetShortcut]&echo;URL=https://ayinedjimi-consultants.fr)>%%s
goto config
::# ======================== REGISTRY QUERY UTILITY ========================
:reg_query [USAGE] call :reg_query "HKCU\Volatile Environment" Value variable
(for /f "tokens=2*" %%R in ('reg query "%~1" /v "%~2" /se "," 2^>nul') do set "%~3=%%S")& exit /b
::# ======================== PRE-FLIGHT CHECKS ========================
:preflight
echo;[%date% %time%] Running pre-flight checks... >> "%LOGFILE%"
set /a PREFLIGHT_OK=1
::# Check 1: Admin rights
fltmc >nul 2>nul
if %errorlevel% neq 0 (
%<%:4f " [WARN] "%>>% & %<%:0f " Not running as Administrator - will self-elevate "%>%
echo;[%date% %time%] WARN: Not admin, will self-elevate >> "%LOGFILE%"
)
::# Check 2: Disk space on system drive (need at least 12GB)
set "FREE_GB=0"
for /f "tokens=*" %%a in ('powershell -nop -ep bypass -c "try{$d=(Get-PSDrive $env:SystemDrive[0]).Free/1GB;[math]::Floor($d)}catch{0}"') do set "FREE_GB=%%a"
if %FREE_GB%0 lss 120 (
%<%:4f " [FAIL] "%>>% & %<%:0f " Insufficient disk space: %FREE_GB% GB free, need 12 GB minimum "%>%
echo;[%date% %time%] FAIL: Only %FREE_GB% GB free disk space >> "%LOGFILE%"
set /a PREFLIGHT_OK=0
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " Disk space: %FREE_GB% GB free "%>%
echo;[%date% %time%] OK: %FREE_GB% GB free disk space >> "%LOGFILE%"
)
::# Check 3: Disk space on TEMP drive (need at least 8GB)
set "TEMP_GB=0"
for /f "tokens=*" %%a in ('powershell -nop -ep bypass -c "try{$t=[io.path]::GetTempPath();$d=(Get-PSDrive ($t[0])).Free/1GB;[math]::Floor($d)}catch{0}"') do set "TEMP_GB=%%a"
if %TEMP_GB%0 lss 80 (
%<%:3f " [WARN] "%>>% & %<%:0f " TEMP drive low: %TEMP_GB% GB free, 8 GB recommended "%>%
echo;[%date% %time%] WARN: TEMP drive only %TEMP_GB% GB free >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " TEMP drive: %TEMP_GB% GB free "%>%
echo;[%date% %time%] OK: TEMP drive %TEMP_GB% GB free >> "%LOGFILE%"
)
::# Check 4: Internet connectivity and DNS
set "NET_OK=0"
ping -n 1 -w 3000 download.microsoft.com >nul 2>nul && set "NET_OK=1"
if "%NET_OK%"=="0" ping -n 1 -w 3000 8.8.8.8 >nul 2>nul && set "NET_OK=2"
if "%NET_OK%"=="0" (
%<%:4f " [FAIL] "%>>% & %<%:0f " No network connectivity - check internet connection "%>%
echo;[%date% %time%] FAIL: No network at all (ping 8.8.8.8 + download.microsoft.com failed) >> "%LOGFILE%"
set /a PREFLIGHT_OK=0
) else if "%NET_OK%"=="2" (
%<%:3f " [WARN] "%>>% & %<%:0f " DNS issue: 8.8.8.8 OK but download.microsoft.com unreachable "%>%
echo;[%date% %time%] WARN: DNS or proxy issue - can ping 8.8.8.8 but not download.microsoft.com >> "%LOGFILE%"
%<%:3f " "%>>% & %<%:0f " Check: DNS, proxy, firewall, WSUS blocking Microsoft CDN "%>%
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " Internet connectivity verified "%>%
echo;[%date% %time%] OK: Internet reachable >> "%LOGFILE%"
)
::# Check 4b: Test actual HTTPS download capability
set "HTTPS_OK=0"
powershell -nop -ep bypass -c "try{[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;$r=[Net.WebRequest]::Create('https://download.microsoft.com').GetResponse();$r.Close();exit 0}catch{Write-Host $_.Exception.Message;exit 1}" >nul 2>nul && set "HTTPS_OK=1"
if "%HTTPS_OK%"=="0" (
%<%:3f " [WARN] "%>>% & %<%:0f " HTTPS to download.microsoft.com failed - check proxy/TLS/firewall "%>%
echo;[%date% %time%] WARN: HTTPS test failed to download.microsoft.com >> "%LOGFILE%"
for /f "tokens=*" %%a in ('powershell -nop -ep bypass -c "try{[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;(Invoke-WebRequest 'https://download.microsoft.com' -UseBasicParsing -TimeoutSec 5).StatusCode}catch{$_.Exception.Message}"') do (
echo;[%date% %time%] HTTPS detail: %%a >> "%LOGFILE%"
%<%:3f " "%>>% & %<%:0f " Detail: %%a "%>%
)
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " HTTPS download capability verified "%>%
echo;[%date% %time%] OK: HTTPS to download.microsoft.com works >> "%LOGFILE%"
)
::# Check 5: PowerShell version and execution policy
set "PS_VER=0"
for /f "tokens=*" %%a in ('powershell -nop -ep bypass -c "$PSVersionTable.PSVersion.Major"') do set "PS_VER=%%a"
if %PS_VER%0 lss 30 (
%<%:3f " [WARN] "%>>% & %<%:0f " PowerShell %PS_VER% detected, v3+ recommended "%>%
echo;[%date% %time%] WARN: PowerShell v%PS_VER% (v3+ recommended) >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " PowerShell v%PS_VER% "%>%
echo;[%date% %time%] OK: PowerShell v%PS_VER% >> "%LOGFILE%"
)
::# Check 6: No conflicting processes
set "CONFLICT="
for %%p in (SetupHost.exe SetupPrep.exe) do tasklist /fi "imagename eq %%p" 2>nul | find /i "%%p" >nul && set "CONFLICT=%%p"
tasklist 2>nul | find /i "MediaCreationTool" >nul && set "CONFLICT=MediaCreationTool"
if defined CONFLICT (
%<%:4f " [WARN] "%>>% & %<%:0f " %CONFLICT% is already running - may cause conflicts "%>%
echo;[%date% %time%] WARN: %CONFLICT% already running >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " No conflicting processes "%>%
echo;[%date% %time%] OK: No conflicting processes >> "%LOGFILE%"
)
::# Check 7: Pending reboot
set "REBOOT_PENDING=0"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" >nul 2>nul && set "REBOOT_PENDING=1"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" >nul 2>nul && set "REBOOT_PENDING=1"
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations >nul 2>nul && set "REBOOT_PENDING=1"
if %REBOOT_PENDING% equ 1 (
%<%:4f " [WARN] "%>>% & %<%:0f " System reboot pending - upgrade may fail, reboot first "%>%
echo;[%date% %time%] WARN: Reboot pending >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " No pending reboot "%>%
echo;[%date% %time%] OK: No pending reboot >> "%LOGFILE%"
)
::# Check 8: Battery check for laptops
set "ON_BATTERY=0"
for /f "tokens=*" %%a in ('powershell -nop -ep bypass -c "try{$b=(Get-WmiObject Win32_Battery -ea 0);if($b -and $b.BatteryStatus -eq 1){'1'}else{'0'}}catch{'0'}"') do set "ON_BATTERY=%%a"
if %ON_BATTERY% equ 1 (
%<%:4f " [WARN] "%>>% & %<%:0f " Running on battery - plug in AC power before upgrading "%>%
echo;[%date% %time%] WARN: Running on battery >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " Power supply OK "%>%
echo;[%date% %time%] OK: Power supply OK >> "%LOGFILE%"
)
echo;
if %PREFLIGHT_OK% equ 0 (
%<%:4f " Pre-flight checks FAILED "%>>% & %<%:0f " Fix issues above before continuing "%>%
echo;[%date% %time%] Pre-flight checks FAILED >> "%LOGFILE%"
echo;& pause & exit /b 1
)
%<%:2f " Pre-flight checks PASSED "%>%
echo;[%date% %time%] Pre-flight checks PASSED >> "%LOGFILE%"
echo;
exit /b 0
::# ======================== PREPARE SYSTEM ========================
::# Active fixes: stops conflicting services, removes upgrade blocks, enables TLS
::# Called AFTER elevation, BEFORE MCT download
:prepare_system
echo;
%<%:5f " Preparing system for upgrade... "%>%
echo;[%date% %time%] Preparing system... >> "%LOGFILE%"
::# Fix 1: Enable and start BITS service (required for downloads)
sc query BITS | find /i "RUNNING" >nul 2>nul
if %errorlevel% neq 0 (
sc config BITS start= demand >nul 2>nul
net start BITS >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " BITS service started "%>%
echo;[%date% %time%] FIX: BITS service started >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " BITS service running "%>%
)
::# Fix 2: Stop Windows Update service (prevents conflicts during upgrade)
net stop wuauserv >nul 2>nul
net stop cryptSvc >nul 2>nul
net stop msiserver >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " Windows Update services stopped "%>%
echo;[%date% %time%] FIX: Stopped wuauserv, cryptSvc, msiserver >> "%LOGFILE%"
::# Fix 3: Disable WaaSMedicSvc (Windows Update Medic - auto-restarts WU on 1903+)
if %OS_VERSION%0 geq 183620 (
sc stop WaaSMedicSvc >nul 2>nul
sc config WaaSMedicSvc start= disabled >nul 2>nul
rem Also disable via registry - more reliable than sc on some builds
reg add "HKLM\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" /v Start /t reg_dword /d 4 /f >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " WaaSMedicSvc (Update Medic) disabled "%>%
echo;[%date% %time%] FIX: WaaSMedicSvc disabled >> "%LOGFILE%"
)
::# Fix 4: Remove WSUS redirection (allow direct Microsoft downloads)
set "WSUS_WAS_SET=0"
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v WUServer >nul 2>nul && set "WSUS_WAS_SET=1"
if %WSUS_WAS_SET% equ 1 (
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v UseWUServer /t reg_dword /d 0 /f >nul 2>nul
net stop wuauserv >nul 2>nul & net start wuauserv >nul 2>nul & net stop wuauserv >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " WSUS bypassed (UseWUServer=0) - will restore after "%>%
echo;[%date% %time%] FIX: WSUS bypassed >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " No WSUS configured "%>%
)
::# Fix 5: Remove Group Policy upgrade blocks
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v TargetReleaseVersion /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v TargetReleaseVersionInfo /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DisableOSUpgrade /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade" /v AllowOSUpgrade /f >nul 2>nul
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DisableWUfBSafeguards /t reg_dword /d 1 /f >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " Group Policy upgrade blocks removed "%>%
echo;[%date% %time%] FIX: GP upgrade blocks removed >> "%LOGFILE%"
::# Fix 6: Enable TLS 1.2 system-wide for .NET (required on 1507-1607 for HTTPS downloads)
reg add "HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319" /v SchUseStrongCrypto /t reg_dword /d 1 /f >nul 2>nul
reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319" /v SchUseStrongCrypto /t reg_dword /d 1 /f >nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\.NETFramework\v2.0.50727" /v SystemDefaultTlsVersions /t reg_dword /d 1 /f >nul 2>nul
reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v2.0.50727" /v SystemDefaultTlsVersions /t reg_dword /d 1 /f >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " TLS 1.2 enabled system-wide (.NET) "%>%
echo;[%date% %time%] FIX: TLS 1.2 enabled system-wide >> "%LOGFILE%"
::# Fix 7: Clean old Appraiser data (prevents stale compat blocks)
if exist "%SystemRoot%\appcompat\appraiser\*.sdb" (
del /f /q "%SystemRoot%\appcompat\appraiser\*.sdb" >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " Old Appraiser compatibility data cleaned "%>%
echo;[%date% %time%] FIX: Appraiser data cleaned >> "%LOGFILE%"
) else (
%<%:2f " [ OK ] "%>>% & %<%:0f " No stale Appraiser data "%>%
)
::# Fix 8: Clear pending reboot flags (so setup will start)
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " Pending reboot flags cleared "%>%
echo;[%date% %time%] FIX: Reboot pending flags cleared >> "%LOGFILE%"
::# Fix 9: Add Defender exclusion for work directory
powershell -nop -ep bypass -c "try{Add-MpPreference -ExclusionPath '%WORK%' -ea 0}catch{}" >nul 2>nul
%<%:6f " [FIX ] "%>>% & %<%:0f " Defender exclusion added for %WORK% "%>%
echo;[%date% %time%] FIX: Defender exclusion for %WORK% >> "%LOGFILE%"
echo;
%<%:2f " System preparation complete "%>%
echo;[%date% %time%] System preparation complete >> "%LOGFILE%"
echo;
exit /b 0
::# ======================== PROCESS ========================
:process
call :preflight
if %errorlevel% neq 0 exit /b 1
if %PRE%0 lss 1 goto choice-0
if %PRE% equ 1 (set "PRESET=Full Auto Upgrade" & set /a AUTO=1)
if %PRE% equ 2 (set "PRESET=Auto Upgrade")
if %PRE% equ 3 (set "PRESET=Auto ISO")
if %PRE% equ 4 (set "PRESET=Auto USB")
if %PRE% equ 5 (set "PRESET=Select" & set EDITION=& set LANGCODE=& set ARCH=& set KEY=)
if %PRE% equ 6 (set "PRESET=MCT Defaults" & set EDITION=& set LANGCODE=& set ARCH=& set KEY=)
if %PRE% equ 6 (goto noelevate_lp) else set set=%MCT%.%PRE%
fltmc>nul||(set A=/d /x /c set "ROOT=%ROOT%"^& start "AlwaysUpdate" "%~f0" %* %set%& powershell -nop -ep bypass -c start -verb runas cmd $env:A;&exit)
:noelevate_lp
::# Prepare system (stop WU, fix WSUS, enable TLS, clean appraiser, etc.)
call :prepare_system
::# Apply hardware bypass for ALL versions (not just Win11)
reg add "HKLM\SYSTEM\Setup\LabConfig" /f /v BypassTPMCheck /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SYSTEM\Setup\LabConfig" /f /v BypassSecureBootCheck /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SYSTEM\Setup\LabConfig" /f /v BypassCPUCheck /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SYSTEM\Setup\LabConfig" /f /v BypassRAMCheck /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SYSTEM\Setup\LabConfig" /f /v BypassStorageCheck /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SYSTEM\Setup\MoSetup" /f /v AllowUpgradesWithUnsupportedTPMorCPU /d 1 /t reg_dword >nul 2>nul
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f /v DisableWUfBSafeguards /d 1 /t reg_dword >nul 2>nul
mkdir "%WORK%\MCT" >nul 2>nul & attrib -R -S -H "%WORK%" /D
pushd "%WORK%\MCT" || (echo;FATAL: Cannot access %WORK%\MCT & pause & exit /b 1)
del /f /q products.* *.key EI.cfg PID.txt auto.cmd AutoUnattend.xml >nul 2>nul
set /a latest=0 & if exist latest set /p latest=<latest
echo;20260328>latest & if %latest% lss 20211116 del /f /q products*.* MediaCreationTool*.exe >nul 2>nul
::# edition fallback (IoTEnterpriseS must come before IoTEnterprise to avoid partial match)
(set MEDIA_EDITION=%MEDIA_EDITION:Eval=%)
(set MEDIA_EDITION=%MEDIA_EDITION:Embedded=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:IoTEnterpriseS=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:IoTEnterprise=Enterprise%)
(set MEDIA_EDITION=%MEDIA_EDITION:EnterpriseS=Enterprise%)
if %VER% leq 16299 (set MEDIA_EDITION=%MEDIA_EDITION:ProfessionalWorkstation=Enterprise%)
if %VER% leq 16299 (set MEDIA_EDITION=%MEDIA_EDITION:ProfessionalEducation=Education%)
if %VER% leq 10586 (set MEDIA_EDITION=%MEDIA_EDITION:Enterprise=Professional%)
if %VER% leq 15063 if %INSERT_BUSINESS%0 lss 1 (set MEDIA_EDITION=%MEDIA_EDITION:Enterprise=Professional%)
if %VER% leq 10586 if %UNHIDE_BUSINESS%0 lss 1 (set MEDIA_EDITION=%MEDIA_EDITION:Education=Professional%)
if %VER% neq 15063 (set MEDIA_EDITION=%MEDIA_EDITION:Cloud=Professional%)
::# generic key preset
for %%s in (%MEDIA_EDITION%) do for %%K in (
V3WVW-N2PV2-CGWC3-34QGF-VMJ2C.Cloud NH9J3-68WK7-6FB93-4K3DF-DJ4F6.CloudN
YTMG3-N6DKC-DKB77-7M9GH-8HVX7.Core 4CPRK-NM3K3-X6XXQ-RXX86-WXCHW.CoreN
BT79Q-G7N6G-PGBYW-4YWX6-6F4BT.CoreSingleLanguage N2434-X9D7W-8PF6X-8DV9T-8TYMD.CoreCountrySpecific
VK7JG-NPHTM-C97JM-9MPGT-3V66T.Professional 2B87N-8KFHP-DKV6R-Y2C8J-PKCKT.ProfessionalN
8PTT6-RNW4C-6V7J2-C2D3X-MHBPB.ProfessionalEducation GJTYN-HDMQY-FRR76-HVGC7-QPF8P.ProfessionalEducationN
DXG7C-N36C4-C4HTG-X4T3X-2YV77.ProfessionalWorkstation WYPNQ-8C467-V2W6J-TX4WX-WT2RQ.ProfessionalWorkstationN
YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY.Education 84NGF-MHBT6-FXBX8-QWJK7-DRR8H.EducationN
NPPR9-FWDCX-D2C8J-H872K-2YT43.Enterprise DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4.EnterpriseN
) do if /i %%~xK equ .%%s set MEDIA_EDITION=%%~xK& call set MEDIA_EDITION=%%MEDIA_EDITION:.=%%& set "MEDIA_KEY=%%~nK"
::# detected / selected media preset
if defined EDITION (set EDITION=%MEDIA_EDITION%)
if "%MEDIA_EDITION%" neq "%OS_EDITION%" (set REG_EDITION=%MEDIA_EDITION%) else (set "REG_EDITION=")
set "CONSUMER=%MEDIA_EDITION:Enterprise=%"
if "%CONSUMER%" equ "%MEDIA_EDITION%" (set CFG=Consumer) else (set CFG=Business)
if not defined EDITION (set UNSTAGED=1& set STAGED=) else (set UNSTAGED=& set STAGED=%MEDIA_EDITION%)
if defined STAGED (set MEDIA_CFG=%STAGED%) else (set MEDIA_CFG=%CFG%)
set MEDIA=& for %%s in (%LANGCODE%%EDITION%%ARCH%%KEY%) do (set MEDIA=%%s)
if defined MEDIA for %%s in (%MEDIA_LANGCODE%) do (set LANGCODE=%%s)
if defined MEDIA for %%s in (%MEDIA_EDITION%) do (set EDITION=%%s)
if defined MEDIA for %%s in (%MEDIA_ARCH%) do (set ARCH=%%s)
if defined MEDIA for %%s in (%MEDIA_KEY%) do (if not defined KEY set KEY=%%s)
if %VER% geq 22000 (set MEDIA_ARCH=x64& if defined ARCH set ARCH=x64)
::# labels
if %VER% geq 22000 (set X=11& set VIS=21H2) else (set X=10& set VIS=%VID%)
if %VER% geq 22621 (set X=11& set VIS=22H2)
if %VER% geq 22631 (set X=11& set VIS=23H2)
if %VER% geq 26100 (set X=11& set VIS=24H2)
if %VER% geq 26200 (set X=11& set VIS=25H2)
::# refresh screen with banner
cls
echo;
echo; ===========================================================================
echo; AlwaysUpdate v1.1 - (c) 2026 Ayi NEDJIMI Consultants
echo; https://ayinedjimi-consultants.fr
echo; ===========================================================================
echo;
%<%:f0 " Windows %X% Version "%>>% & %<%:5f " %VIS% "%>>% & %<%:f1 " %CB% "%>>%
if %PRE% leq 4 %<%:6f " %MEDIA_LANGCODE% "%>>% & %<%:9f " %MEDIA_CFG% "%>>% & %<%:2f " %MEDIA_ARCH% "%>%
echo;
::# diagnostic info for troubleshooting
echo;[%date% %time%] --- Diagnostic --- >> "%LOGFILE%"
echo;[%date% %time%] Script: %~f0 >> "%LOGFILE%"
echo;[%date% %time%] WorkDir: %CD% >> "%LOGFILE%"
echo;[%date% %time%] PRESET=%PRESET% VER=%VER% VID=%VID% VIS=%VIS% >> "%LOGFILE%"
echo;[%date% %time%] EXE=%EXE% >> "%LOGFILE%"
echo;[%date% %time%] CAB=%CAB% FWLINK_MCT=%FWLINK_MCT% >> "%LOGFILE%"
echo;[%date% %time%] Edition=%MEDIA_EDITION% Lang=%MEDIA_LANGCODE% Arch=%MEDIA_ARCH% >> "%LOGFILE%"
%<%:8f " Preset: %PRESET% "%>>% & %<%:8f " Target: Windows %X% %VIS% "%>%
echo;
if "%LANG%"=="FR" (
%<%:8f " Script : %~f0 "%>%
%<%:8f " Dossier: %CD% "%>%
) else (
%<%:8f " Script : %~f0 "%>%
%<%:8f " WorkDir: %CD% "%>%
)
echo;
::# verify critical functions exist in script
set "DIAG_OK=1"
findstr /b /c:":DOWNLOAD" "%~f0" >nul 2>nul || (
%<%:4f " [ERREUR] Label :DOWNLOAD manquant dans le script "%>%
echo;[%date% %time%] FATAL: :DOWNLOAD label missing >> "%LOGFILE%"
set "DIAG_OK=0"
)
findstr /b /c:":PRODUCTS_XML" "%~f0" >nul 2>nul || (
%<%:4f " [ERREUR] Label :PRODUCTS_XML manquant dans le script "%>%
echo;[%date% %time%] FATAL: :PRODUCTS_XML label missing >> "%LOGFILE%"
set "DIAG_OK=0"
)
if "%DIAG_OK%"=="0" (
%<%:4f " Script corrompu - retelecharger depuis GitHub "%>%
echo;& pause & exit /b 1
)
::# verify PowerShell can execute embedded functions
powershell -nop -ep bypass -c "exit 0" >nul 2>nul
if %errorlevel% neq 0 (
%<%:4f " [ERREUR] PowerShell ne peut pas executer de scripts "%>%
echo;[%date% %time%] FATAL: PowerShell execution blocked >> "%LOGFILE%"
echo;& pause & exit /b 1
)
::# download MCT and CAB/XML with progress
%<%:6f " Downloading components... "%>%
echo;[%date% %time%] Downloading MCT and product catalog >> "%LOGFILE%"
if defined EXE echo;%EXE% & call :DOWNLOAD "%EXE%" MediaCreationTool%VID%.exe
if defined XML echo;%XML% & call :DOWNLOAD "%XML%" products%VID%.xml
if defined CAB echo;%CAB% & call :DOWNLOAD "%CAB%" products%VID%.cab
::# For 24H2/25H2: obtain products catalog by running fwlink MCT briefly
::# The fwlink MCT downloads the latest catalog from Microsoft on startup,
::# before any hardware checks. We capture it and kill the MCT.
set "FALLBACK_CAB=https://download.microsoft.com/download/6/2/b/62b47bc5-1b28-4bfa-9422-e7a098d326d4/products_win11_20231208.cab"
if defined FWLINK_MCT if not defined CAB (
%<%:6f " Obtaining latest products catalog from Microsoft... "%>%
echo;[%date% %time%] Downloading fwlink MCT to obtain catalog >> "%LOGFILE%"
call :DOWNLOAD "%FWLINK_MCT%" MCT_fwlink.exe
if exist MCT_fwlink.exe (
set "0=%~f0"& powershell -nop -ep bypass -c "iex ([io.file]::ReadAllText($env:0) -split '[:]capture_products_catalog')[1];"
del /f /q MCT_fwlink.exe >nul 2>nul
)
if exist products.xml (
%<%:2f " Products catalog obtained successfully "%>%
echo;[%date% %time%] Products catalog captured from fwlink MCT >> "%LOGFILE%"
) else (
if "%LANG%"=="FR" (
%<%:3f " [WARN] "%>>% & %<%:0f " Catalogue non obtenu - fallback sur le catalogue 23H2 "%>%
) else (
%<%:3f " [WARN] "%>>% & %<%:0f " Catalog not obtained - falling back to 23H2 catalog "%>%
)
echo;[%date% %time%] WARN: Catalog capture failed, using 23H2 fallback >> "%LOGFILE%"
call :DOWNLOAD "%FALLBACK_CAB%" products%VID%.cab
)
)
if exist products%VID%.xml copy /y products%VID%.xml products.xml >nul 2>nul
if exist products%VID%.cab del /f /q products%VID%.xml >nul 2>nul
if exist products%VID%.cab (
expand.exe -R products%VID%.cab -F:* . >nul 2>nul
if not exist products.xml echo;[%date% %time%] WARN: CAB expand failed, trying cabextract >> "%LOGFILE%" & extrac32 /Y /E products%VID%.cab >nul 2>nul
)
set "/hint=Check urls in browser | del ESD dir | use powershell v3.0+ | unblock powershell | enable BITS serv"
echo;& set err=& for %%s in (products.xml MediaCreationTool%VID%.exe) do if not exist %%s set err=1
if defined err (%<%:4f " ERROR "%>>% & %<%:0f " %/hint% "%>%) else if not defined err %<%:2f " Downloads complete "%>%
if defined err (
echo;[%date% %time%] ERROR: Download failed >> "%LOGFILE%"
del /f /q products%VID%.* MediaCreationTool%VID%.exe 2>nul & pause & exit /b 1
)
echo;[%date% %time%] Downloads complete >> "%LOGFILE%"
::# configure products.xml
set "XML_SIZE_BEFORE=0"
for %%f in (products.xml) do set "XML_SIZE_BEFORE=%%~zf"
call :PRODUCTS_XML
for %%f in (products.xml) do if %%~zf lss 100 (
echo;[%date% %time%] WARN: products.xml mangled by PRODUCTS_XML, restoring >> "%LOGFILE%"
%<%:3f " [WARN] "%>>% & %<%:0f " products.xml config failed, using original "%>%
if exist products%VID%.cab expand.exe -R products%VID%.cab -F:* . >nul 2>nul
)
::# repack XML into CAB
makecab products.xml products.cab >nul
::# MCT Defaults - just launch and quit
if "MCT Defaults" equ "%PRESET%" (start MediaCreationTool%VID%.exe /Selfhost& exit /b)
::# setup options
if defined EDITION (set EDITION_SWITCH=%EDITION%) else (set EDITION_SWITCH=)
if not defined MEDIA (set LANGCODE=%MEDIA_LANGCODE%& set EDITION=%MEDIA_EDITION%& set ARCH=%MEDIA_ARCH%)
if defined UNSTAGED (set KEY=)
if %VER% gtr 15063 (set MEDIA_SEL=/MediaLangCode %LANGCODE% /MediaEdition %EDITION% /MediaArch %ARCH%) else (set MEDIA_SEL=)
if "Select" equ "%PRESET%" (set MEDIA_SEL=)
set MOPTIONS=/Action CreateMedia %MEDIA_SEL% /Pkey Defer %OPTIONS% /SkipSummary /Eula Accept
set AOPTIONS=/Auto Upgrade /MigChoice Upgrade %OPTIONS% /SkipSummary /Eula Accept
set MAKE_OPTIONS=/SelfHost& for %%s in (%MOPTIONS%) do call set MAKE_OPTIONS=%%MAKE_OPTIONS%% %%s
set AUTO_OPTIONS=/SelfHost& for %%s in (%AOPTIONS%) do call set AUTO_OPTIONS=%%AUTO_OPTIONS%% %%s
::# generate PID.txt
for %%s in (Workstation WorkstationN Education EducationN) do if "Professional%%s" equ "%EDITION%" set "KEY="
if not defined PKEY if "Enterprise" equ "%EDITION%" set "KEY="
if not defined KEY (del /f /q PID.txt 2>nul) else (echo;[PID]& echo;Value=%KEY%& echo;;Edition=%EDITION%)>PID.txt
::# generate EI.cfg
if not defined KEY if %VER% geq 22000 (echo;[Channel]& echo;_Default)>EI.cfg
::# generate auto.cmd
set "0=%~f0"& powershell -nop -ep bypass -c "iex ([io.file]::ReadAllText($env:0) -split '[:]generate_auto_cmd')[1];"
if not exist auto.cmd (
echo;[%date% %time%] WARN: auto.cmd generation failed >> "%LOGFILE%"
%<%:3f " [WARN] "%>>% & %<%:0f " auto.cmd not generated - PowerShell may be broken "%>%
)
::# generate AutoUnattend.xml
set "0=%~f0"& powershell -nop -ep bypass -c "iex ([io.file]::ReadAllText($env:0) -split '[:]generate_AutoUnattend_xml')[1];"
::# cleanup stale
dism /cleanup-wim >nul 2>nul
::# start Assisted MCT
echo;
%<%:5f " Starting Media Creation Tool with progress tracking... "%>%
echo;[%date% %time%] Starting Assisted MCT >> "%LOGFILE%"
set "0=%~f0" & powershell -nop -ep bypass -c "iex ([io.file]::ReadAllText($env:0) -split '[:]Assisted_MCT')[1];"
if %errorlevel% neq 0 (
echo;[%date% %time%] ERROR: Assisted MCT returned error %errorlevel% >> "%LOGFILE%"
%<%:4f " ERROR "%>>% & %<%:0f " MCT process failed. Check %LOGFILE% for details "%>%
)
if not defined DEF if %hide% neq 1 pause >nul
EXIT
::# ======================== ASSISTED MCT (PowerShell) ========================
::--------------------------------------------------------------------------------------------------------------------------------
:Assisted_MCT
#:: AlwaysUpdate v1.1 - Enhanced Assisted MCT with progress bar
$host.ui.rawui.windowtitle = "AlwaysUpdate v1.1 - $env:PRESET $env:X $env:DEF"; $ErrorActionPreference = 0
[io.path]::GetTempPath(),$env:TEMP,$env:TMP |% { if ($env:ROOT -like "*$_*") {$env:ROOT=$env:WORK} }
$DRIVE = [environment]::SystemDirectory[0]; $WD = $DRIVE+':\ESD'; $WS = $DRIVE+':\$WINDOWS.~WS\Sources'; $DIR = $WS+'\Windows'
$ESD = $null; $USB = $null; $ISO = "$env:ROOT\$env:X $env:VIS $env:MEDIA_CFG $env:MEDIA_ARCH $env:MEDIA_LANGCODE.iso"
$LOGFILE = $env:LOGFILE
if ('Auto Upgrade' -eq $env:PRESET -or 'Full Auto Upgrade' -eq $env:PRESET) {$ISO = [io.path]::GetTempPath() + "~temporary.iso"}
del $ISO -force -ea 0 >$null
if (test-path $ISO) {write-host " ERROR! " -fore Red -nonew; write-host "$ISO is read-only or in use`r`n"; sleep 5; return}
cd -Lit("$env:WORK\MCT")
#:: Progress bar function
$script:lastLoggedPct = -1
function Show-ProgressBar ($pct, $status, $color = 'Cyan') {
$pct = [math]::Max(0, [math]::Min(100, $pct))
$width = 50; $filled = [math]::Floor($pct * $width / 100); $empty = $width - $filled
$bar = '#' * $filled + '-' * $empty
$line = ("`r [$bar] {0,3}% - $status" -f $pct).PadRight(120)
write-host -nonew -fore $color $line
Write-Progress -Activity "AlwaysUpdate v1.1" -Status $status -PercentComplete $pct
if ($pct -ne $script:lastLoggedPct) {
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] Progress: $pct% - $status"
$script:lastLoggedPct = $pct
}
}
Show-ProgressBar 5 "Initializing..."
#:: workaround for version 1703 and earlier
if ($env:VER -le 15063 -and $null -ne $env:REG_EDITION) {
$K = '"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"'; $E = $env:REG_EDITION
cmd /d /x /c "(reg add $K /v EditionID /d $E /reg:32 /f & reg delete $K /v ProductName /reg:32 /f) >nul 2>nul"
cmd /d /x /c "(reg add $K /v EditionID /d $E /reg:64 /f & reg delete $K /v ProductName /reg:64 /f) >nul 2>nul"
}
#:: setup file watcher
function Watcher {
$A = $args; $Exe = $A[0]; $File = $A[1]; $Folder = $A[2]; $Subdirs = @($false,$true)[$A[3] -eq 'all']
$P = mkdir $Folder -force -ea 0; if (!(test-path $P)) {return 1}; $W = new-object IO.FileSystemWatcher; $W.Path = $P.FullName
$W.Filter = $File; $W.IncludeSubdirectories = $Subdirs; $W.NotifyFilter = 125; $W.EnableRaisingEvents = $true; $ret = 1
while ($true) {
try { $get = $W.WaitForChanged(15, 15000) } catch { mkdir $Folder -ea 0 >$null; continue }
if (-not $get.TimedOut) { write-host -fore Gray $get.ChangeType,$get.Name; $ret = 0;break} else {if ($Exe.HasExited) {break}}
} ; $W.Dispose(); return $ret
}
#:: load ui automation
Show-ProgressBar 8 "Loading UI automation..."
$an = 'UIAutomationClientsideProviders','UIAutomationClient','UIAutomationTypes','System.Windows.Forms','Microsoft.VisualBasic'
$ca = { [Windows.Automation.ClientSettings]::RegisterClientSideProviderAssembly($re[0].GetName()) }
$re = $an |% { [Reflection.Assembly]::LoadWithPartialName("$_") } ; try { & $ca } catch { & $ca }
$cp = [Windows.Automation.AutomationElement]::ClassNameProperty
$bt = "Button","ComboBox","Edit" |% {new-object Windows.Automation.PropertyCondition($cp, $_)}
$null = new-item -path function: -name "Enter" -value { $app = get-process "SetupHost" -ea 0
if ($null -ne $app) {[Microsoft.VisualBasic.Interaction]::AppActivate($app.Id)}; [Windows.Forms.SendKeys]::SendWait("{ENTER}") }
$id = 0; if ('Auto USB' -ne $env:PRESET) {$id = 1}
$sw = "ShowWindowAsync"; $dm = [AppDomain]::CurrentDomain."DefineDynami`cAssembly"(1,1)."DefineDynami`cModule"(1)
$dt = $dm."Defin`eType"("AlwaysUpdate",1179913,[ValueType]); $ptr = (get-process -pid $PID).MainWindowHandle.gettype()
$dt."DefinePInvok`eMethod"($sw,"user`32",8214,1,[void],@($ptr,[int]),1,4) >$null; $nt = $dt."Creat`eType"()
new-item -path function: -name "ShowWindow" -value {$nt."G`etMethod"($sw).invoke(0,@($args[0],$args[1]))} >$null
Show-ProgressBar 10 "Launching Media Creation Tool..."
#:: start monitoring
:mct while ($true) {
$set = get-process SetupHost -ea 0; if ($set) {$set.Kill()}
$mct = start -passthru "$env:WORK\MCT\MediaCreationTool${env:VID}.exe" $env:MAKE_OPTIONS; if ($null -eq $mct) {break :mct}
while ($null -eq (get-process SetupHost -ea 0)) {if ($mct.HasExited) {break :mct}; sleep -m 200 }
$set = get-process SetupHost -ea 0; if ($null -eq $set) {break :mct}
while ($set.MainWindowHandle -eq 0) { if ($mct.HasExited) {break :mct}; $set.Refresh(); sleep -m 200 }
Show-ProgressBar 15 "MCT GUI loaded, configuring..."
#:: automate GUI
if ('Select' -ne $env:PRESET) { try {
$win = [Windows.Automation.AutomationElement]::FromHandle($set.MainWindowHandle); $nr = $win.FindAll(5, $bt[0]).Count
if ($env:VER -le 15063) {while ($win.FindAll(5,$bt[1]).Count -lt 3) {if ($mct.HasExited) {break :mct}; sleep -m 200}; Enter}
while ($win.FindAll(5,$bt[0]).Count -le $nr) {if ($mct.HasExited) {break :mct}; sleep -m 200}; $all = $win.FindAll(5,$bt[0])
$all[$id].GetCurrentPattern([Windows.Automation.SelectionItemPattern]::Pattern).Select();$all[$all.Count-1].SetFocus(); Enter
if ('Auto USB' -ne $env:PRESET) {
while ($win.FindAll(5,$bt[2]).Count -le 0) {if ($mct.HasExited) {break :mct};sleep -m 50}; $val = $win.FindAll(5,$bt[2])[0]
[Windows.Forms.SendKeys]::SendWait(" "); $val.GetCurrentPattern([Windows.Automation.ValuePattern]::Pattern).SetValue($ISO)
[Windows.Forms.SendKeys]::Flush(); $b = $win.FindAll(5, $bt[0]); ($b |? {$_.Current.AutomationId -eq 1}).SetFocus(); Enter
}
} catch {} }
Show-ProgressBar 20 "MCT configured, preparing download..."
if ($null -ne $env:DEF -and 'Auto Upgrade' -ne $env:PRESET -and 'Full Auto Upgrade' -ne $env:PRESET) {break :mct}
#:: get target from state file (timeout: 10 min)
$ready = $false; $task = "PreDownload"; $action = "GetWebSetupUserInput"; $timeout = [datetime]::Now.AddMinutes(10)
while (-not $ready) {
if ([datetime]::Now -gt $timeout) {write-host "`n TIMEOUT waiting for MCT state" -fore Red; break :mct}
try {[xml]$xml = get-content "$WS\Panther\windlp.state.xml" -ea Stop} catch {sleep -m 2000; continue}
foreach ($t in $xml.WINDLP.TASK) { if ($t.Name -eq $task) { foreach ($a in $t.ACTION) { if ($a.ActionName -eq $action) {
if ($null -ne $a.DownloadUrlX86) {$ESD = $a.DownloadUrlX86}
if ($null -ne $a.DownloadUrlX64) {$ESD = $a.DownloadUrlX64}
if ($null -ne $a.TargetISO) {$ISO = $a.TargetISO; $ready = $true}
$u = $a.TargetUsbDrive; if ($null -ne $u -and $u -gt 0) {$USB = [char][Convert]::ToInt32($u, 16) + ":"; $ready = $true}
}}}} ; if ($mct.HasExited) {break :mct}; sleep -m 1000
}
if ($mct.HasExited) {break :mct}
if ('Auto Upgrade' -ne $env:PRESET -and 'Full Auto Upgrade' -ne $env:PRESET -and $null -eq $USB) {write-host "`n"; Show-ProgressBar 25 "Target: $ISO"}
if ('Auto Upgrade' -ne $env:PRESET -and 'Full Auto Upgrade' -ne $env:PRESET -and $null -ne $USB) {write-host "`n"; Show-ProgressBar 25 "Target: $USB"}
if ('Auto Upgrade' -eq $env:PRESET -or 'Full Auto Upgrade' -eq $env:PRESET) {write-host "`n"; Show-ProgressBar 25 "Preparing upgrade media..."}
$label = "${env:X}_${env:VIS}" + ($ESD -split '(?=_client)')[1]
$label = $label -replace '_clientconsumer','' -replace '_clientbusiness','' -replace 'fre_','_' -replace '.esd',''
sleep 10; powershell -win $env:hide -nop -c ";"
if ($mct.HasExited) {break :mct}
#:: watch ESD download with progress
write-host "`n"
Show-ProgressBar 30 "Downloading Windows ESD image..."
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] ESD download started"
Watcher $mct "*.esd" $WD all >$null; if ($mct.HasExited) {break :mct}
Show-ProgressBar 60 "Creating installation media..."
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] Media creation started"
Watcher $mct "*.wim" $WS all >$null; if ($mct.HasExited) {break :mct}
#:: add to media: EI.cfg, PID.txt, auto.cmd, $ISO$ dir
if ($null -eq $env:DEF) {
Show-ProgressBar 70 "Adding bypass files to media..."
pushd -lit "$env:ROOT"
$f1 = '$ISO$'; if (test-path $f1) {xcopy /CYBERHIQ $f1 "$DIR" >$null; write-host -fore Gray "`nAddDirs $f1"} ; popd
pushd -lit "$env:WORK"
if (-not (test-path "$DIR\auto.cmd")) {
$f2 = "MCT\auto.cmd"; if (test-path $f2) {copy -path $f2 -dest $DIR -force >$null; write-host -fore Gray "AddFile $f2"}
}
foreach ($P in "$DIR\x86\sources","$DIR\x64\sources","$DIR\sources") {
if (!(test-path "$P\setupprep.exe")) {continue}
if (-not (test-path "$DIR\EI.cfg") -and ($ESD -like '*_ret_*')) {
$f3 = "MCT\EI.cfg"; if (test-path $f3) {copy -path $f3 -dest $P -force >$null; write-host -fore Gray "AddFile $f3"}
}
if (-not (test-path "$DIR\PID.txt")) {
$f4 = "MCT\PID.txt"; if (test-path $f4) {copy -path $f4 -dest $P -force >$null; write-host -fore Gray "AddFile $f4"}
}
} ; popd
}
#:: watch media layout with realistic progress
Show-ProgressBar 75 "Converting install.esd..."
$ready = $false; $task = "MediaCreate"; $action = "Layout"; $timeout2 = [datetime]::Now.AddMinutes(60)
while (-not $ready) {
if ([datetime]::Now -gt $timeout2) {write-host "`n TIMEOUT waiting for media layout" -fore Red; break :mct}
try {[xml]$xml = get-content "$WS\Panther\windlp.state.xml" -ea Stop} catch {sleep -m 5000; continue}
foreach ($t in $xml.WINDLP.TASK) { if ($t.Name -eq $task) { foreach ($a in $t.ACTION) { if ($a.ActionName -eq $action) {
$total = $a.ProgressTotal; $current = $a.ProgressCurrent
if ($null -ne $total -and 0 -ne $total -and $total -eq $current) {$ready = $true}
try {if ($null -ne $current -and 0 -ne $current) {$done = [Convert]::ToInt64($current, 16)} else {$done = 0}} catch {$done = 0}
$rpct = 75 + [math]::Floor($done * 10 / 100)
if ($rpct -gt 85) {$rpct = 85}
Show-ProgressBar $rpct "Converting install.esd ($done%)..."
}}}} ; if ($mct.HasExited) {break :mct}; sleep -m 10000
}
$action = "IsoLayout"; if ($null -ne $USB) {$action = "UsbLayout"}
Show-ProgressBar 85 "Layout: $action..."
#:: watch usb layout progress
if ($null -ne $USB) {
$ready = $false; $task = "MediaCreate"; $action = "UsbLayout"; $size = 0; $almost = 0; $foreground = 0
while (-not $ready) {
sleep -m 5000; if ($mct.HasExited) {break :mct}
try {[xml]$xml = get-content "$WS\Panther\windlp.state.xml" -ea Stop} catch {continue}
foreach ($t in $xml.WINDLP.TASK) { if ($t.Name -eq $task) { foreach ($a in $t.ACTION) { if ($a.ActionName -eq $action) {
$total = $a.ProgressTotal; $current = $a.ProgressCurrent
if ($null -ne $total -and 0 -ne $total -and $total -eq $current) {$ready = $true}
try {if ($size -eq 0) {$size = [Math]::Ceiling([Convert]::ToInt64($total, 16)/1048576); $almost = $size * 0.8}
$done = [Math]::Ceiling([Convert]::ToInt64($current, 16)/1048576)} catch {$done = 0}
if ($foreground -eq 0 -and $done -gt $almost) {
$set = get-process SetupHost -ea 0; $SetupHost = $set.MainWindowHandle; powershell -win 0 -nop -c ";"
ShowWindow $SetupHost 0; ShowWindow (get-process -Id $PID).MainWindowHandle 1; $foreground = 1
}
if ($size -gt 0) {$wpct = 85 + [math]::Floor($done * 10 / $size)} else {$wpct = 85}
if ($wpct -gt 95) {$wpct = 95}
Show-ProgressBar $wpct "Writing USB: ${done}/${size} MB..."
}}}}
}
}
#:: kill MCT before temporary iso finish (for Win11 or Auto Upgrade)
if ($env:VER -ge 22000 -or 'Auto Upgrade' -eq $env:PRESET -or 'Full Auto Upgrade' -eq $env:PRESET) {
$mct.Kill(); $s = get-process SetupPrep,SetupHost -ea 0; if ($s) { foreach ($setup in $s) {$setup.Kill()} }
powershell -win 0 -nop -c ";"; ShowWindow (get-process -Id $PID).MainWindowHandle 1
sleep 3; cmd /d /x /c "dism /cleanup-wim >nul 2>nul"; del $ISO -force -ea 0 >$null
}
break :mct
}
#:: undo registry workaround for 1703-
if ($env:VER -le 15063 -and $null -ne $env:REG_EDITION) {
$K = '"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"'; $E = $env:OS_EDITION; $P = $env:OS_PRODUCT
cmd /d /x /c "(reg add $K /v EditionID /d $E /reg:32 /f & reg add $K /v ProductName /d $P /reg:32 /f) >nul 2>nul"
cmd /d /x /c "(reg add $K /v EditionID /d $E /reg:64 /f & reg add $K /v ProductName /d $P /reg:64 /f) >nul 2>nul"
}
#:: error check
if (-not (test-path "$DIR\sources\ws.dat")) {
if ((get-process SetupHost -ea 0) -and $null -ne $env:DEF) {return}
powershell -win 0 -nop -c ";"; ShowWindow (get-process -Id $PID).MainWindowHandle 1
pushd -lit "$env:WORK"; cmd /d /x /c "pushd c:\ & rmdir /s /q ""$DIR"" >nul 2>nul & del /f /q ""$WS\*.*"" >nul 2>nul"
write-host "`n ERROR! " -fore Red -nonew; write-host "setup terminated unexpectedly"
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] ERROR: setup terminated unexpectedly"
write-host " Check log at: $LOGFILE`r`n"; sleep 7; return
}
Show-ProgressBar 90 "Applying hardware bypass to media..."
#:: skip 11 upgrade checks: 0-byte appraiserres.dll
if ($env:VER -ge 22000) {
cmd /d /x /c "cd.>""$DIR\sources\appraiserres.dll"""
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] Applied appraiserres.dll bypass"
}
#:: Auto Upgrade / Full Auto Upgrade
if ('Auto Upgrade' -eq $env:PRESET -or 'Full Auto Upgrade' -eq $env:PRESET) {
Show-ProgressBar 92 "Starting auto upgrade..."
cd -Lit("$env:WORK\MCT"); cmd /d /x /c "call ""$env:WORK\MCT\auto.cmd"" ""$DIR"""; sleep 7; return
}
#:: skip win11 upgrade checks in boot.wim
if ($env:VER -ge 22000 -and (test-path "$DIR\sources\boot.wim")) {
Show-ProgressBar 92 "Patching boot.wim for hardware bypass..."
Add-Content $LOGFILE "[$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')] Patching boot.wim"
rmdir "$WD\MOUNT" -re -force -ea 0; mkdir "$WD\MOUNT" -force -ea 0 >$null; $winsetup = "$WD\MOUNT\sources\winsetup.dll"
dism.exe /mount-wim /wimfile:"$DIR\sources\boot.wim" /index:2 /mountdir:"$WD\MOUNT"; write-host
if (-not (test-path "$DIR\AutoUnattend.xml")) {
$f5 = "$env:WORK\MCT\AutoUnattend.xml"
if (test-path $f5) {write-host importing file: $f5; copy -path $f5 -dest "$WD\MOUNT" -force >$null}
}
try { takeown.exe /f $winsetup /a >$null; icacls.exe $winsetup /grant *S-1-5-32-544:f; attrib -R -S $winsetup
$patch = '/commit'; [io.file]::OpenWrite($winsetup).close() } catch {$patch = '/discard'}
if ($patch -eq '/commit') {
$b = [io.file]::ReadAllBytes($winsetup); $h = [BitConverter]::ToString($b) -replace '-'