-
Notifications
You must be signed in to change notification settings - Fork 6
/
MAS.cmd
10505 lines (8551 loc) · 435 KB
/
MAS.cmd
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
@::b879-random
@set masver=2.8
@setlocal DisableDelayedExpansion
@echo off
:: For command line switches, check mass grave[.]dev/command_line_switches
:: If you want to better understand script, read from MAS separate files version.
::============================================================================
::
:: Homepage: mass grave[.]dev
:: Email: mas.help@outlook.com
::
::============================================================================
::========================================================================================================================================
:: Set environment variables, it helps if they are misconfigured in the system
setlocal EnableExtensions
setlocal DisableDelayedExpansion
set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
set "SysPath=%SystemRoot%\System32"
set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
if exist "%SystemRoot%\Sysnative\reg.exe" (
set "SysPath=%SystemRoot%\Sysnative"
set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%"
)
set "ComSpec=%SysPath%\cmd.exe"
set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
set re1=
set re2=
set "_cmdf=%~f0"
for %%# in (%*) do (
if /i "%%#"=="re1" set re1=1
if /i "%%#"=="re2" set re2=1
)
:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows
:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows
if exist %SystemRoot%\Sysnative\cmd.exe if not defined re1 (
setlocal EnableDelayedExpansion
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" %* re1"
exit /b
)
:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows
if exist %SystemRoot%\SysArm32\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (
setlocal EnableDelayedExpansion
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" %* re2"
exit /b
)
::========================================================================================================================================
set "blank="
set "mas=ht%blank%tps%blank%://mass%blank%grave.dev/"
:: Check if Null service is working, it's important for the batch script
sc query Null | find /i "RUNNING"
if %errorlevel% NEQ 0 (
echo:
echo Null service is not running, script may crash...
echo:
echo:
echo Help - %mas%troubleshoot
echo:
echo:
ping 127.0.0.1 -n 20
)
cls
:: Check LF line ending
pushd "%~dp0"
>nul findstr /v "$" "%~nx0" && (
echo:
echo Error - Script either has LF line ending issue or an empty line at the end of the script is missing.
echo:
echo:
echo Help - %mas%troubleshoot
echo:
echo:
ping 127.0.0.1 -n 20 >nul
popd
exit /b
)
popd
::========================================================================================================================================
cls
color 07
title Microsoft_Activation_Scripts %masver%
set _args=
set _elev=
set _unattended=0
set _args=%*
if defined _args set _args=%_args:"=%
if defined _args set _args=%_args:re1=%
if defined _args set _args=%_args:re2=%
if defined _args (
for %%A in (%_args%) do (
if /i "%%A"=="-el" set _elev=1
)
)
if defined _args echo "%_args%" | find /i "/" >nul && set _unattended=1
::========================================================================================================================================
set "nul1=1>nul"
set "nul2=2>nul"
set "nul6=2^>nul"
set "nul=>nul 2>&1"
call :dk_setvar
if %winbuild% LSS 7600 (
%nceline%
echo Unsupported OS version detected [%winbuild%].
echo Project is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.
goto dk_done
)
::========================================================================================================================================
:: Fix special character limitations in path name
set "_work=%~dp0"
if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
set "_batf=%~f0"
set "_batp=%_batf:'=''%"
set _PSarg="""%~f0""" -el %_args%
set _PSarg=%_PSarg:'=''%
set "_ttemp=%userprofile%\AppData\Local\Temp"
setlocal EnableDelayedExpansion
::========================================================================================================================================
echo "!_batf!" | find /i "!_ttemp!" %nul1% && (
if /i not "!_work!"=="!_ttemp!" (
%eline%
echo The script was launched from the temp folder.
echo You are most likely running the script directly from the archive file.
echo:
echo Extract the archive file and launch the script from the extracted folder.
goto dk_done
)
)
::========================================================================================================================================
:: Check PowerShell
REM :PowerShellTest: $ExecutionContext.SessionState.LanguageMode :PowerShellTest:
cmd /c "%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':PowerShellTest:\s*';iex ($f[1])"" | find /i "FullLanguage" %nul1% || (
%eline%
cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode""
echo:
cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode"" | find /i "FullLanguage" %nul1% && (
echo Failed to run Powershell command but Powershell is working.
echo:
cmd /c "%psc% ""$av = Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { if ($i.displayName -notlike '*windows*') { $n += $i.displayName } }; if ($n) { Write-Host ('Installed 3rd party Antivirus might be blocking the script - ' + ($n -join ', ')) -ForegroundColor White -BackgroundColor Blue }"""
echo:
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
) || (
echo PowerShell is not working. Aborting...
echo If you have applied restrictions on Powershell then undo those changes.
echo:
set fixes=%fixes% %mas%fix_powershell
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%fix_powershell"
)
goto dk_done
)
::========================================================================================================================================
:: Elevate script as admin and pass arguments and preventing loop
%nul1% fltmc || (
if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && exit /b
%eline%
echo This script needs admin rights.
echo Right click on this script and select 'Run as administrator'.
goto dk_done
)
::========================================================================================================================================
:: Disable QuickEdit and launch from conhost.exe to avoid Terminal app
if %winbuild% GEQ 17763 (
set terminal=1
) else (
set terminal=
)
:: Check if script is running in Terminal app
set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
set r2=%r1% [void]$TB.DefinePInvokeMethod('GetConsoleWindow', 'kernel32.dll', 22, 1, [IntPtr], @(), 1, 3).SetImplementationFlags(128);
set r3=%r2% [void]$TB.DefinePInvokeMethod('SendMessageW', 'user32.dll', 22, 1, [IntPtr], @([IntPtr], [UInt32], [IntPtr], [IntPtr]), 1, 3).SetImplementationFlags(128);
set d1=%r3% $hIcon = $TB.CreateType(); $hWnd = $hIcon::GetConsoleWindow();
set d2=%d1% echo $($hIcon::SendMessageW($hWnd, 127, 0, 0) -ne [IntPtr]::Zero);
if defined terminal (
%psc% "%d2%" %nul2% | find /i "True" %nul1% && set terminal=
)
if defined ps32onArm goto :skipQE
if %_unattended%==1 goto :skipQE
for %%# in (%_args%) do (if /i "%%#"=="-qedit" goto :skipQE)
if defined terminal (
set "launchcmd=start conhost.exe %psc%"
) else (
set "launchcmd=%psc%"
)
:: Disable QuickEdit in current session
set "d1=$t=[AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);"
set "d2=$t.DefinePInvokeMethod('GetStdHandle', 'kernel32.dll', 22, 1, [IntPtr], @([Int32]), 1, 3).SetImplementationFlags(128);"
set "d3=$t.DefinePInvokeMethod('SetConsoleMode', 'kernel32.dll', 22, 1, [Boolean], @([IntPtr], [Int32]), 1, 3).SetImplementationFlags(128);"
set "d4=$k=$t.CreateType(); $b=$k::SetConsoleMode($k::GetStdHandle(-10), 0x0080);"
%launchcmd% "%d1% %d2% %d3% %d4% & cmd.exe '/c' '!_PSarg! -qedit'" && (exit /b) || (set terminal=1)
:skipQE
::========================================================================================================================================
:: Check for updates
set -=
set old=
for /f "delims=[] tokens=2" %%# in ('ping -4 -n 1 updatecheck.mass%-%grave.dev') do (
if not "%%#"=="" (echo "%%#" | find "127.69" %nul1% && (echo "%%#" | find "127.69.%masver%" %nul1% || set old=1))
)
if defined old (
echo ________________________________________________
%eline%
echo Your version of MAS [%masver%] is outdated.
echo ________________________________________________
echo:
if not %_unattended%==1 (
echo [1] Get Latest MAS
echo [0] Continue Anyway
echo:
call :dk_color %_Green% "Choose a menu option using your keyboard [1,0] :"
choice /C:10 /N
if !errorlevel!==2 rem
if !errorlevel!==1 (start ht%-%tps://github.com/mass%-%gravel/Microsoft-Acti%-%vation-Scripts & start %mas% & exit /b)
)
)
::========================================================================================================================================
if not exist "%SystemRoot%\Temp\" mkdir "%SystemRoot%\Temp" %nul%
:: Run script with parameters in unattended mode
set _elev=
if defined _args echo "%_args%" | find /i "/S" %nul% && (set "_silent=%nul%") || (set _silent=)
if defined _args echo "%_args%" | find /i "/" %nul% && (
echo "%_args%" | find /i "/HWID" %nul% && (setlocal & cls & (call :HWIDActivation %_args% %_silent%) & endlocal)
echo "%_args%" | find /i "/KMS38" %nul% && (setlocal & cls & (call :KMS38Activation %_args% %_silent%) & endlocal)
echo "%_args%" | find /i "/K-" %nul% && (setlocal & cls & (call :KMSActivation %_args% %_silent%) & endlocal)
echo "%_args%" | find /i "/Ohook" %nul% && (setlocal & cls & (call :OhookActivation %_args% %_silent%) & endlocal)
exit /b
)
::========================================================================================================================================
setlocal DisableDelayedExpansion
:: Check desktop location
set desktop=
for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do call set "desktop=%%b"
if not defined desktop for /f "delims=" %%a in ('%psc% "& {write-host $([Environment]::GetFolderPath('Desktop'))}"') do call set "desktop=%%a"
set "_pdesk=%desktop:'=''%"
setlocal EnableDelayedExpansion
if not defined desktop (
%eline%
echo Unable to detect Desktop location, aborting...
goto dk_done
)
::========================================================================================================================================
:MainMenu
cls
color 07
title Microsoft %blank%Activation %blank%Scripts %masver%
if not defined terminal mode 76, 33
echo:
echo:
echo:
echo:
echo: ______________________________________________________________
echo:
echo: Activation Methods:
echo:
echo: [1] HWID ^| Windows ^| Permanent
echo: [2] Ohook ^| Office ^| Permanent
echo: [3] KMS38 ^| Windows ^| Year 2038
echo: [4] Online KMS ^| Windows / Office ^| 180 Days
echo: __________________________________________________
echo:
echo: [5] Check Activation Status
echo: [6] Change Windows Edition
echo: [7] Change Office Edition
echo: __________________________________________________
echo:
echo: [8] Troubleshoot
echo: [9] Extras
echo: [H] Help
echo: [0] Exit
echo: ______________________________________________________________
echo:
call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,5,6,7,8,9,H,0] :"
choice /C:123456789H0 /N
set _erl=%errorlevel%
if %_erl%==11 exit /b
if %_erl%==10 start %mas%troubleshoot & goto :MainMenu
if %_erl%==9 goto :Extras
if %_erl%==8 setlocal & call :troubleshoot & cls & endlocal & goto :MainMenu
if %_erl%==7 setlocal & call :change_offedition & cls & endlocal & goto :MainMenu
if %_erl%==6 setlocal & call :change_winedition & cls & endlocal & goto :MainMenu
if %_erl%==5 setlocal & call :check_actstatus & cls & endlocal & goto :MainMenu
if %_erl%==4 setlocal & call :KMSActivation & cls & endlocal & goto :MainMenu
if %_erl%==3 setlocal & call :KMS38Activation & cls & endlocal & goto :MainMenu
if %_erl%==2 setlocal & call :OhookActivation & cls & endlocal & goto :MainMenu
if %_erl%==1 setlocal & call :HWIDActivation & cls & endlocal & goto :MainMenu
goto :MainMenu
::========================================================================================================================================
:Extras
cls
title Extras
if not defined terminal mode 76, 30
echo:
echo:
echo:
echo:
echo:
echo: ______________________________________________________
echo:
echo: [1] Extract $OEM$ Folder
echo:
echo: [2] Download Genuine Windows / Office
echo: ____________________________________________
echo:
echo: [0] Go to Main Menu
echo: ______________________________________________________
echo:
call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,0] :"
choice /C:120 /N
set _erl=%errorlevel%
if %_erl%==3 goto :MainMenu
if %_erl%==2 start %mas%genuine-installation-media & goto :Extras
if %_erl%==1 goto :Extract$OEM$
goto :Extras
::========================================================================================================================================
:Extract$OEM$
cls
title Extract $OEM$ Folder
if not defined terminal mode 76, 30
if exist "!desktop!\$OEM$\" (
%eline%
echo $OEM$ folder already exists on the Desktop.
echo _____________________________________________________
echo:
call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
choice /c 0 /n
goto :Extras
)
:Extract$OEM$2
cls
title Extract $OEM$ Folder
if not defined terminal mode 78, 30
echo:
echo:
echo:
echo:
echo: Extract $OEM$ folder on the desktop
echo: ________________________________________________________
echo:
echo: [1] HWID
echo: [2] Ohook
echo: [3] KMS38
echo: [4] Online KMS
echo:
echo: [5] HWID ^(Windows^) ^+ Ohook ^(Office^)
echo: [6] HWID ^(Windows^) ^+ Online KMS ^(Office^)
echo: [7] KMS38 ^(Windows^) ^+ Ohook ^(Office^)
echo: [8] KMS38 ^(Windows^) ^+ Online KMS ^(Office^)
echo: [9] Online KMS ^(Windows^) ^+ Ohook ^(Office^)
echo:
call :dk_color2 %_White% " [R] " %_Green% "ReadMe"
echo: [0] Go Back
echo: ________________________________________________________
echo:
call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard:"
choice /C:123456789R0 /N
set _erl=%errorlevel%
if %_erl%==11 goto:Extras
if %_erl%==10 start %mas%oem-folder &goto:Extract$OEM$2
if %_erl%==9 (set "_oem=Online KMS [Windows] + Ohook [Office]" & set "para=/K-Windows /Ohook" &goto:Extract$OEM$3)
if %_erl%==8 (set "_oem=KMS38 [Windows] + Online KMS [Office]" & set "para=/KMS38 /K-Office" &goto:Extract$OEM$3)
if %_erl%==7 (set "_oem=KMS38 [Windows] + Ohook [Office]" & set "para=/KMS38 /Ohook" &goto:Extract$OEM$3)
if %_erl%==6 (set "_oem=HWID [Windows] + Online KMS [Office]" & set "para=/HWID /K-Office" &goto:Extract$OEM$3)
if %_erl%==5 (set "_oem=HWID [Windows] + Ohook [Office]" & set "para=/HWID /Ohook" &goto:Extract$OEM$3)
if %_erl%==4 (set "_oem=Online KMS" & set "para=/K-WindowsOffice" &goto:Extract$OEM$3)
if %_erl%==3 (set "_oem=KMS38" & set "para=/KMS38" &goto:Extract$OEM$3)
if %_erl%==2 (set "_oem=Ohook" & set "para=/Ohook" &goto:Extract$OEM$3)
if %_erl%==1 (set "_oem=HWID" & set "para=/HWID" &goto:Extract$OEM$3)
goto :Extract$OEM$2
::========================================================================================================================================
:Extract$OEM$3
cls
set "_dir=!desktop!\$OEM$\$$\Setup\Scripts"
md "!_dir!\"
:: Add random data on top to create unique file which helps in avoiding AV's detections
%psc% "$f=[io.file]::ReadAllText('!_batp!'); [io.file]::WriteAllText('!_pdesk!\$OEM$\$$\Setup\Scripts\MAS_AIO.cmd', '@::RANDOM-' + [Guid]::NewGuid().Guid + [Environment]::NewLine + $f, [System.Text.Encoding]::ASCII)"
(
echo @echo off
echo fltmc ^>nul ^|^| exit /b
echo call "%%~dp0MAS_AIO.cmd" %para%
echo cd \
echo ^(goto^) 2^>nul ^& ^(if "%%~dp0"=="%%SystemRoot%%\Setup\Scripts\" rd /s /q "%%~dp0"^)
)>"!_dir!\SetupComplete.cmd"
set _error=
if not exist "!_dir!\MAS_AIO.cmd" set _error=1
if not exist "!_dir!\SetupComplete.cmd" set _error=1
if defined _error (
%eline%
echo The script failed to create the $OEM$ folder.
if exist "!desktop!\$OEM$\.*" rmdir /s /q "!desktop!\$OEM$\" %nul%
) else (
echo:
call :dk_color %Blue% "%_oem%"
call :dk_color %Green% "$OEM$ folder was successfully created on your Desktop."
)
echo "%_oem%" | find /i "KMS38" 1>nul && (
echo:
echo To KMS38 activate Server Cor/Acor editions ^(No GUI Versions^),
echo Check this page %mas%oem-folder
)
echo ___________________________________________________________________
echo:
call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
choice /c 0 /n
goto Extras
:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
:HWIDActivation
:: To activate, run the script with "/HWID" parameter or change 0 to 1 in below line
set _act=0
:: To disable changing edition if current edition doesn't support HWID activation, change the value to 1 from 0 or run the script with "/HWID-NoEditionChange" parameter
set _NoEditionChange=0
:: If value is changed in above lines or parameter is used then script will run in unattended mode
::========================================================================================================================================
cls
color 07
title HWID Activation %masver%
set _args=
set _elev=
set _unattended=0
set _args=%*
if defined _args set _args=%_args:"=%
if defined _args (
for %%A in (%_args%) do (
if /i "%%A"=="/HWID" set _act=1
if /i "%%A"=="/HWID-NoEditionChange" set _NoEditionChange=1
if /i "%%A"=="-el" set _elev=1
)
)
for %%A in (%_act% %_NoEditionChange%) do (if "%%A"=="1" set _unattended=1)
::========================================================================================================================================
if %winbuild% LSS 10240 (
%eline%
echo Unsupported OS version detected [%winbuild%].
echo HWID Activation is only supported on Windows 10/11.
echo:
call :dk_color %Blue% "Use Online KMS activation option."
goto dk_done
)
if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
%eline%
echo HWID Activation is not supported on Windows Server.
call :dk_color %Blue% "Use KMS38 or Online KMS activation option."
goto dk_done
)
setlocal EnableDelayedExpansion
::========================================================================================================================================
cls
if not defined terminal (
mode 110, 34
if exist "%SysPath%\spp\store_test\" mode 134, 34
)
title HWID Activation %masver%
echo:
echo Initializing...
call :dk_chkmal
for %%# in (
sppsvc.exe
ClipUp.exe
) do (
if not exist %SysPath%\%%# (
%eline%
echo [%SysPath%\%%#] file is missing, aborting...
echo:
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
goto dk_done
)
)
::========================================================================================================================================
set spp=SoftwareLicensingProduct
set sps=SoftwareLicensingService
call :dk_ckeckwmic
call :dk_checksku
call :dk_product
call :dk_sppissue
::========================================================================================================================================
:: Check if system is permanently activated or not
call :dk_checkperm
if defined _perm (
cls
echo ___________________________________________________________________________________________
echo:
call :dk_color2 %_White% " " %Green% "%winos% is already permanently activated."
call :dk_color2 %_White% " " %Gray% "Activation is not required."
echo ___________________________________________________________________________________________
if %_unattended%==1 goto dk_done
echo:
choice /C:10 /N /M "> [1] Activate Anyway [0] %_exitmsg% : "
if errorlevel 2 exit /b
)
cls
::========================================================================================================================================
:: Check Evaluation version
if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% && (
%eline%
echo [%winos% ^| %winbuild%]
echo:
echo Evaluation editions cannot be activated outside of their evaluation period.
echo:
set fixes=%fixes% %mas%evaluation_editions
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%evaluation_editions"
goto dk_done
)
)
::========================================================================================================================================
set error=
cls
echo:
call :dk_showosinfo
:: Check Internet connection
set _int=
for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
)
if not defined _int (
%psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
)
if defined _int (
echo Checking Internet Connection [Connected%ping_f%]
) else (
set error=1
call :dk_color %Red% "Checking Internet Connection [Not Connected]"
call :dk_color %Blue% "Internet is required for HWID activation."
)
::========================================================================================================================================
echo Initiating Diagnostic Tests...
set "_serv=ClipSVC wlidsvc sppsvc KeyIso LicenseManager Winmgmt"
:: Client License Service (ClipSVC)
:: Microsoft Account Sign-in Assistant
:: Software Protection
:: CNG Key Isolation
:: Windows License Manager Service
:: Windows Management Instrumentation
call :dk_errorcheck
::========================================================================================================================================
:: Detect Key
set key=
set altkey=
set changekey=
set altapplist=
set altedition=
set notworking=
call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
if defined allapps call :hwiddata key
if not defined key (
for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getactivationid\:.*';iex ($f[1])"') do (set altapplist=%%a)
if defined altapplist call :hwiddata key
)
if defined notworking call :hwidfallback
if not defined key call :hwidfallback
if defined altkey (set key=%altkey%&set changekey=1&set notworking=)
if defined notworking if defined notfoundaltactID (
call :dk_color %Red% "Checking Alternate Edition For HWID [%altedition% Activation ID Not Found]"
)
if not defined key (
%eline%
echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
if not defined skunotfound (
echo This product does not support HWID activation.
echo Make sure you are using the latest version of the script.
echo If you are, then try KMS38 activation option.
set fixes=%fixes% %mas%
echo %mas%
) else (
echo Required license files not found in %SysPath%\spp\tokens\skus\
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
)
echo:
goto dk_done
)
if defined notworking set error=1
::========================================================================================================================================
:: Install key
echo:
if defined changekey (
call :dk_color %Blue% "[%altedition%] edition product key will be used to enable HWID activation."
echo:
)
if defined winsub (
call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%]."
echo:
)
call :dk_inskey "[%key%]"
::========================================================================================================================================
:: Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries
for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Name %nul6%') do set "name=%%b"
for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Nation %nul6%') do set "nation=%%b"
set regionchange=
if not "%name%"=="US" (
set regionchange=1
%psc% "Set-WinHomeLocation -GeoId 244" %nul%
if !errorlevel! EQU 0 (
echo Changing Windows Region To USA [Successful]
) else (
call :dk_color %Red% "Changing Windows Region To USA [Failed]"
)
)
::==========================================================================================================================================
:: Generate GenuineTicket.xml and apply
:: In some cases clipup -v -o method fails and in some cases service restart method fails as well
:: To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)
set "tdir=%ProgramData%\Microsoft\Windows\ClipSVC\GenuineTicket"
if not exist "%tdir%\" md "%tdir%\" %nul%
if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" del /f /q "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" %nul%
call :hwiddata ticket
copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
if not exist "%tdir%\GenuineTicket.xml" (
call :dk_color %Red% "Generating GenuineTicket.xml [Failed, aborting...]"
echo [%encoded%]
if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
goto :dl_final
) else (
echo Generating GenuineTicket.xml [Successful]
)
set "_xmlexist=if exist "%tdir%\GenuineTicket.xml""
%_xmlexist% (
%psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
%_xmlexist% timeout /t 2 %nul%
%_xmlexist% timeout /t 2 %nul%
%_xmlexist% (
set error=1
if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
call :dk_color %Gray% "Installing GenuineTicket.xml [Failed with ClipSVC service restart, wait...]"
)
)
copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
clipup -v -o
set rebuildinfo=
if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Checking ClipSVC tokens.dat [Not Found]"
)
%_xmlexist% (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Installing GenuineTicket.xml [Failed With clipup -v -o]"
)
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Checking Ticket Migration [Failed]"
)
if not defined altapplist if not defined showfix if defined rebuildinfo (
set showfix=1
call :dk_color %Blue% "%_fixmsg%"
)
if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
::==========================================================================================================================================
call :dk_product
echo:
echo Activating...
call :dk_act
call :dk_checkperm
if defined _perm (
echo:
call :dk_color %Green% "%winos% is permanently activated with a digital license."
goto :dl_final
)
::==========================================================================================================================================
:: Clear store ID related registry to fix activation if Internet is connected
set "_ident=HKU\S-1-5-19\SOFTWARE\Microsoft\IdentityCRL"
if defined _int (
reg delete "%_ident%" /f %nul%
reg query "%_ident%" %nul% && (
echo:
set error=1
call :dk_color %Red% "Deleting IdentityCRL Registry [Failed] [%_ident%]"
)
for %%# in (wlidsvc LicenseManager sppsvc) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null")
call :dk_refresh
call :dk_act
call :dk_checkperm
)
::==========================================================================================================================================
:: Extended licensing servers tests incase error not found and activation failed
if %keyerror% EQU 0 if not defined _perm if defined _int (
set resfail=
ipconfig /flushdns %nul%
set "tls=[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;"
for %%# in (
login.live.com/ppsecure/deviceaddcredential.srf
purchase.mp.microsoft.com/v7.0/users/me/orders
) do if not defined resfail (
set "d1=Add-Type -AssemblyName System.Net.Http;"
set "d1=!d1! $client = [System.Net.Http.HttpClient]::new();"
set "d1=!d1! $response = $client.GetAsync('https://%%#').GetAwaiter().GetResult();"
set "d1=!d1! $response.Content.ReadAsStringAsync().GetAwaiter().GetResult()"
%psc% "!tls! !d1!" %nul2% | findstr /i "PurchaseFD DeviceAddResponse" %nul1% || set resfail=1
)
if not defined resfail (
%psc% "!tls! irm https://licensing.mp.microsoft.com/v7.0/licenses/content -Method POST" | find /i "traceId" %nul1% || set resfail=1
)
if defined resfail (
set error=1
echo:
call :dk_color %Red% "Checking Licensing Servers [Failed to Connect]"
set fixes=%fixes% %mas%licensing-servers-issue
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%licensing-servers-issue"
)
)
::==========================================================================================================================================
if %keyerror% EQU 0 if not defined _perm if defined _int (
reg query "%_ident%" %nul% || (
set error=1
echo:
call :dk_color %Red% "Generating New IdentityCRL Registry [Failed] [%_ident%]"
)
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DisableWindowsUpdateAccess %nul2% | find /i "0x1" %nul% && set wublock=1
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DoNotConnectToWindowsUpdateInternetLocations %nul2% | find /i "0x1" %nul% && set wublock=1
if defined wublock call :dk_color %Red% "Checking Update Blocker In Registry [Found]"
reg query "HKLM\SOFTWARE\Policies\Microsoft\WindowsStore" /v DisableStoreApps %nul2% | find /i "0x1" %nul% && (
set storeblock=1
call :dk_color %Red% "Checking Store Blocker In Registry [Found]"
)
for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type ServiceSidType RequiredPrivileges FailureActions) do if not defined wucorrupt (
reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /v %%G %nul% || set wucorrupt=1
)
for %%G in (Parameters Security TriggerInfo) do if not defined wucorrupt (
reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\%%G %nul% || set wucorrupt=1
)
if defined wucorrupt (
call :dk_color %Red% "Checking Windows Update Registry [Corruption Found]"
) else (
%psc% "Start-Job { Start-Service wuauserv } | Wait-Job -Timeout 20 | Out-Null"
sc query wuauserv | find /i "RUNNING" %nul% || (
set wuerror=1
sc start wuauserv %nul%
call :dk_color %Red% "Starting Windows Update Service [Failed] [!errorlevel!]"
)
)
REM Check Internet related error codes
if not defined wucorrupt if not defined wublock if not defined wuerror if not defined storeblock (
echo "%error_code%" | findstr /i "0x80072e 0x80072f 0x800704cf 0x87e10bcf 0x800705b4" %nul% && (
call :dk_color %Red% "Checking Internet Issues [Found] %error_code%"
set fixes=%fixes% %mas%licensing-servers-issue
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%licensing-servers-issue"
)
)
)
::==========================================================================================================================================
echo:
if defined _perm (
call :dk_color %Green% "%winos% is permanently activated with a digital license."
) else (
call :dk_color %Red% "Activation Failed %error_code%"
if defined notworking (
call :dk_color %Blue% "At the time of writing, HWID Activation is not supported for this product."
call :dk_color %Blue% "Use KMS38 activation option instead."
) else (
if not defined error call :dk_color %Blue% "%_fixmsg%"
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
)
)
::========================================================================================================================================
:dl_final
echo:
if defined regionchange (
%psc% "Set-WinHomeLocation -GeoId %nation%" %nul%
if !errorlevel! EQU 0 (
echo Restoring Windows Region [Successful]
) else (
call :dk_color %Red% "Restoring Windows Region [Failed] [%name% - %nation%]"
)
)
REM if %osSKU%==175 call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
:: Trigger reevaluation of SPP's Scheduled Tasks
if defined _perm (
call :dk_reeval %nul%
)
goto :dk_done
::========================================================================================================================================
:: Set variables
:dk_setvar
set psc=powershell.exe
set winbuild=1
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
set _NCS=1
if %winbuild% LSS 10586 set _NCS=0
if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
echo "%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%" | find /i "ARM64" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)
if %_NCS% EQU 1 (
for /F %%a in ('echo prompt $E ^| cmd') do set "esc=%%a"
set "Red="41;97m""
set "Gray="100;97m""