summaryrefslogtreecommitdiff
path: root/MAS_1.4/Separate-Files-Version/Extras/OEMRET-Install_W10_Key.cmd
blob: 1cc347aca27b2d55fe633f1681f6d4a3d39c22c9 (plain)
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
@setlocal DisableDelayedExpansion
@echo off

:: For unattended mode, run the script with /u parameter.





:: =======================================================================================================
::
::   This script is a part of 'Microsoft Activation Scripts' project.
::
::   Homepages-
::   NsaneForums: (Login Required) https://www.nsaneforums.com/topic/316668-microsoft-activation-scripts/
::   GitHub: https://github.com/massgravel/Microsoft-Activation-Scripts
::   GitLab: https://gitlab.com/massgrave/microsoft-activation-scripts
::
::   Maintained by @WindowsAddict
::
:: =======================================================================================================











::========================================================================================================================================

cls
title Install Windows 10 Retail/OEM Key
set Unattended=
set _args=
set _elev=
set "_arg1=%~1"
if not defined _arg1 goto :NoProgArgs
set "_args=%~1"
set "_arg2=%~2"
if defined _arg2 set "_args=%~1 %~2"
for %%A in (%_args%) do (
if /i "%%A"=="-el" set _elev=1
if /i "%%A"=="/u" set Unattended=1)
:NoProgArgs
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
set "_psc=powershell"
set "nul=1>nul 2>nul"
set "ELine=echo: &echo ==== ERROR ==== &echo:"

::========================================================================================================================================

if %winbuild% LSS 10240 (
%ELine%
echo Unsupported OS version Detected.
echo Project is supported only for Windows 10.
goto Ins_Done
)

::========================================================================================================================================

::  Elevate script as admin and pass arguments and preventing loop
::  Thanks to @hearywarlot [ https://forums.mydigitallife.net/threads/.74332/ ] for the VBS method.
::  Thanks to @abbodi1406 for the powershell method and solving special characters issue in file path name.

%nul% reg query HKU\S-1-5-19 && (
  goto :Passed
  ) || (
  if defined _elev goto :E_Admin
)

set "_batf=%~f0"
set "_vbsf=%temp%\admin.vbs"
set _PSarg="""%~f0""" -el
if defined _args set _PSarg="""%~f0""" -el """%_args%"""

setlocal EnableDelayedExpansion

(
echo Set strArg=WScript.Arguments.Named
echo Set strRdlproc = CreateObject^("WScript.Shell"^).Exec^("rundll32 kernel32,Sleep"^)
echo With GetObject^("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" ^& strRdlproc.ProcessId ^& "'"^)
echo With GetObject^("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" ^& .ParentProcessId ^& "'"^)
echo If InStr ^(.CommandLine, WScript.ScriptName^) ^<^> 0 Then
echo strLine = Mid^(.CommandLine, InStr^(.CommandLine , "/File:"^) + Len^(strArg^("File"^)^) + 8^)
echo End If
echo End With
echo .Terminate
echo End With
echo CreateObject^("Shell.Application"^).ShellExecute "cmd.exe", "/c " ^& chr^(34^) ^& chr^(34^) ^& strArg^("File"^) ^& chr^(34^) ^& strLine ^& chr^(34^), "", "runas", 1
)>"!_vbsf!"

(%nul% cscript //NoLogo "!_vbsf!" /File:"!_batf!" -el "!_args!") && (
del /f /q "!_vbsf!"
exit /b
) || (
del /f /q "!_vbsf!"
%nul% %_psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && (
exit /b
) || (
goto :E_Admin
)
)
exit /b

:E_Admin
%ELine%
echo This script require administrator privileges.
echo To do so, right click on this script and select 'Run as administrator'.
goto Ins_Done

:Passed

mode con: cols=98 lines=30
setlocal EnableDelayedExpansion

::========================================================================================================================================

::  Check Windows OS name

set winos=
for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName 2^>nul') do if not errorlevel 1 set "winos=%%b"
if not defined winos for /f "tokens=2* delims== " %%a in ('"wmic os get caption /value" 2^>nul') do if not errorlevel 1 set "winos=%%b"

::  Check SKU value

set SKU=
for /f "tokens=2 delims==" %%a IN ('"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST" 2^>nul') do if not errorlevel 1 (set osSKU=%%a)
if not defined SKU for /f "tokens=3 delims=." %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v OSProductPfn 2^>nul') do if not errorlevel 1 (set osSKU=%%a)

if "%osSKU%"=="" (
%ELine%
echo SKU value was not detected properly. Aborting...
goto Ins_Done
)

::  Check Windows Edition with SKU value for better accuracy

set osedition=
call :CheckEdition %nul%

if "%osedition%"=="" (
%ELine%
echo [%winos% ^| %winbuild% ^| SKU:%osSKU%] HWID Activation is Not Supported.
goto Ins_Done
)

set key=
call :%osedition% %nul%

if "%key%"=="" (
%ELine%
echo [%winos% ^| %winbuild%] HWID Activation is Not Supported.
goto Ins_Done
)

::========================================================================================================================================

if defined Unattended goto ContinueKeyInsert

cls
echo ___________________________________________________________________________________________
echo:
echo  Install [%winos% ^| %winbuild%] Retail/OEM Key 
echo  [%key%]
echo ___________________________________________________________________________________________
echo:
choice /C:12 /N /M "[1] Continue [2] Exit : "

if errorlevel 2 exit /b
if errorlevel 1 goto ContinueKeyInsert

:ContinueKeyInsert

cls
echo ___________________________________________________________________________________________

::  Thanks to @abbodi1406 for the WMI methods

set slp=SoftwareLicensingProduct
set sls=SoftwareLicensingService
set wApp=55c92734-d682-4d71-983e-d6ec3f16059f

wmic path %sls% where __CLASS='%sls%' call InstallProductKey ProductKey="%key%" %nul% && (
for /f "tokens=2 delims==" %%# in ('wmic path %slp% where "ApplicationID='%wApp%' and PartialProductKey<>null" Get ProductKeyChannel /value 2^>nul') do set "_channel=%%#"
wmic path %sls% where __CLASS='%sls%' call RefreshLicenseStatus %nul%
echo:
echo [%winos% ^| %winbuild%]
call echo Installing %%_channel%% Key [%key%] 
echo [Successful]
) || (
%ELine%
echo Installing Retail/OEM Key [%key%]
echo [Unsuccessful]
)
echo ___________________________________________________________________________________________

::========================================================================================================================================

:Ins_Done
echo:
if defined Unattended (
echo Exiting in 3 seconds...
if %winbuild% LSS 7600 (ping -n 3 127.0.0.1 > nul) else (timeout /t 3)
exit /b
)
echo Press any key to exit...
pause >nul
exit /b

::========================================================================================================================================

::  Check Windows Edition with SKU value for better accuracy

:CheckEdition

for %%# in (
4-Enterprise
27-EnterpriseN
48-Professional
49-ProfessionalN
98-CoreN
99-CoreCountrySpecific
100-CoreSingleLanguage
101-Core
121-Education
122-EducationN
125-EnterpriseS
126-EnterpriseSN
161-ProfessionalWorkstation
162-ProfessionalWorkstationN
164-ProfessionalEducation
165-ProfessionalEducationN
175-ServerRdsh
188-IoTEnterprise
) do for /f "tokens=1,2 delims=-" %%A in ("%%#") do (
if %osSKU%==%%A set "osedition=%%B"
)
exit /b

::========================================================================================================================================

:: Retail/OEM Key List

:Core
set "key=YTMG3-N6DKC-DKB77-7M9GH-8HVX7"
exit /b

:CoreCountrySpecific
set "key=N2434-X9D7W-8PF6X-8DV9T-8TYMD"
exit /b

:CoreN
set "key=4CPRK-NM3K3-X6XXQ-RXX86-WXCHW"
exit /b

:CoreSingleLanguage
set "key=BT79Q-G7N6G-PGBYW-4YWX6-6F4BT"
exit /b

:Education
set "key=YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY"
exit /b

:EducationN
set "key=84NGF-MHBT6-FXBX8-QWJK7-DRR8H"
exit /b

:Enterprise
set "key=XGVPP-NMH47-7TTHJ-W3FW7-8HV2C"
exit /b

:EnterpriseN
set "key=3V6Q6-NQXCX-V8YXR-9QCYV-QPFCT"
exit /b

:EnterpriseS
if "%winbuild%" EQU "10240" set "key=FWN7H-PF93Q-4GGP8-M8RF3-MDWWW"
if "%winbuild%" EQU "14393" set "key=NK96Y-D9CD8-W44CQ-R8YTK-DYJWX"
if "%winbuild%" EQU "17763" set "key=43TBQ-NH92J-XKTM7-KT3KK-P39PB"
exit /b

:EnterpriseSN
if "%winbuild%" EQU "10240" set "key=8V8WN-3GXBH-2TCMG-XHRX3-9766K"
if "%winbuild%" EQU "14393" set "key=2DBW3-N2PJG-MVHW3-G7TDK-9HKR4"
if "%winbuild%" EQU "17763" set "key=M33WV-NHY3C-R7FPM-BQGPT-239PG"
exit /b

:Professional
set "key=VK7JG-NPHTM-C97JM-9MPGT-3V66T"
exit /b

:ProfessionalEducation
set "key=8PTT6-RNW4C-6V7J2-C2D3X-MHBPB"
exit /b

:ProfessionalEducationN
set "key=GJTYN-HDMQY-FRR76-HVGC7-QPF8P"
exit /b

:ProfessionalN
set "key=2B87N-8KFHP-DKV6R-Y2C8J-PKCKT"
exit /b

:ProfessionalWorkstation
set "key=DXG7C-N36C4-C4HTG-X4T3X-2YV77"
exit /b

:ProfessionalWorkstationN
set "key=WYPNQ-8C467-V2W6J-TX4WX-WT2RQ"
exit /b

:ServerRdsh
set "key=NJCF7-PW8QT-3324D-688JX-2YV66"
exit /b

:IoTEnterprise
set "key=XQQYW-NFFMW-XJPBH-K8732-CKFFD"
exit /b

::========================================================================================================================================