From e81490b89c55d7b0477da6e72db36e13f2b15f63 Mon Sep 17 00:00:00 2001 From: WindowsAddict Date: Mon, 25 Sep 2023 19:16:19 +0530 Subject: 1.9 --- MAS/Separate-Files-Version/Change_Edition.cmd | 538 ++++++++++++++------------ 1 file changed, 286 insertions(+), 252 deletions(-) (limited to 'MAS/Separate-Files-Version/Change_Edition.cmd') diff --git a/MAS/Separate-Files-Version/Change_Edition.cmd b/MAS/Separate-Files-Version/Change_Edition.cmd index 140d6a0..d1461ad 100644 --- a/MAS/Separate-Files-Version/Change_Edition.cmd +++ b/MAS/Separate-Files-Version/Change_Edition.cmd @@ -7,7 +7,7 @@ :: :: This script is a part of 'Microsoft_Activation_Scripts' (MAS) project. :: -:: Homepage: massgrave.dev +:: Homepage: mass grave[.]dev :: Email: windowsaddict@protonmail.com :: ::============================================================================ @@ -21,6 +21,13 @@ set _stg=0 ::======================================================================================================================================== +:: Set Path variable, it helps if it is misconfigured in the system + +set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" +if exist "%SystemRoot%\Sysnative\reg.exe" ( +set "PATH=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%PATH%" +) + :: 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 @@ -28,6 +35,10 @@ set "_cmdf=%~f0" for %%# in (%*) do ( if /i "%%#"=="r1" set r1=1 if /i "%%#"=="r2" set r2=1 +if /i "%%#"=="-qedit" ( +reg add HKCU\Console /v QuickEdit /t REG_DWORD /d "1" /f %nul1% +rem check the code below admin elevation to understand why it's here +) ) if exist %SystemRoot%\Sysnative\cmd.exe if not defined r1 ( @@ -44,22 +55,34 @@ start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" %* r2" exit /b ) -:: Set Path variable, it helps if it is misconfigured in the system +::======================================================================================================================================== -set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" -if exist "%SystemRoot%\Sysnative\reg.exe" ( -set "PATH=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%PATH%" +set "blank=" +set "mas=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 - https://%mas%/troubleshoot.html +echo: +echo: +ping 127.0.0.1 -n 10 ) +cls :: Check LF line ending pushd "%~dp0" ->nul findstr /rxc:".*" "%~nx0" -if not %errorlevel%==0 ( +>nul findstr /v "$" "%~nx0" && ( echo: -echo Error: Script either has LF line ending issue, or it failed to read itself. +echo Error: Script either has LF line ending issue or an empty line at the end of the script is missing. echo: -ping 127.0.0.1 -n 6 > nul +ping 127.0.0.1 -n 6 >nul popd exit /b ) @@ -71,24 +94,36 @@ cls color 07 title Change Windows Edition +set _args= set _elev= -if /i "%~1"=="-el" set _elev=1 -set winbuild=1 +set _args=%* +if defined _args set _args=%_args:"=% +if defined _args ( +for %%A in (%_args%) do ( +if /i "%%A"=="-el" set _elev=1 +) +) + +set "nul1=1>nul" +set "nul2=2>nul" +set "nul6=2^>nul" set "nul=>nul 2>&1" + 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 2>nul | find /i "0x0" 1>nul && (set _NCS=0) +if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0) if %_NCS% EQU 1 ( for /F %%a in ('echo prompt $E ^| cmd') do set "esc=%%a" set "Red="41;97m"" set "Gray="100;97m"" set "Green="42;97m"" -set "Magenta="45;97m"" +set "Blue="44;97m"" set "_White="40;37m"" set "_Green="40;92m"" set "_Yellow="40;93m"" @@ -96,7 +131,7 @@ set "_Yellow="40;93m"" set "Red="Red" "white"" set "Gray="Darkgray" "white"" set "Green="DarkGreen" "white"" -set "Magenta="Darkmagenta" "white"" +set "Blue="Blue" "white"" set "_White="Black" "Gray"" set "_Green="Black" "Green"" set "_Yellow="Black" "Yellow"" @@ -111,7 +146,7 @@ if %~z0 GEQ 200000 (set "_exitmsg=Go back") else (set "_exitmsg=Exit") if %winbuild% LSS 7600 ( %nceline% -echo Unsupported OS version detected. +echo Unsupported OS version detected [%winbuild%]. echo Project is supported only for Windows 7/8/8.1/10/11 and their Server equivalent. goto ced_done ) @@ -140,7 +175,7 @@ setlocal EnableDelayedExpansion ::======================================================================================================================================== -echo "!_batf!" | find /i "!_ttemp!" 1>nul && ( +echo "!_batf!" | find /i "!_ttemp!" %nul1% && ( if /i not "!_work!"=="!_ttemp!" ( %eline% echo Script is launched from the temp folder, @@ -155,8 +190,8 @@ goto ced_done :: Elevate script as admin and pass arguments and preventing loop ->nul fltmc || ( -if not defined _elev %nul% %psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && exit /b +%nul1% fltmc || ( +if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && exit /b %eline% echo This script require admin privileges. echo To do so, right click on this script and select 'Run as administrator'. @@ -165,6 +200,20 @@ goto ced_done ::======================================================================================================================================== +:: This code disables QuickEdit for this cmd.exe session only without making permanent changes to the registry +:: It is added because clicking on the script window pauses the operation and leads to the confusion that script stopped due to an error + +for %%# in (%_args%) do (if /i "%%#"=="-qedit" set quedit=1) + +reg query HKCU\Console /v QuickEdit %nul2% | find /i "0x0" %nul1% || if not defined quedit ( +reg add HKCU\Console /v QuickEdit /t REG_DWORD /d "0" /f %nul1% +start cmd.exe /c ""!_batf!" %_args% -qedit" +rem quickedit reset code is added at the starting of the script instead of here because it takes time to reflect in some cases +exit /b +) + +::======================================================================================================================================== + cls mode 98, 30 @@ -189,43 +238,41 @@ echo: :: Check Activation IDs call :dk_actids - +if not defined applist ( +net stop sppsvc /y %nul% +cscript //nologo %windir%\system32\slmgr.vbs /rilc %nul% +if !errorlevel! NEQ 0 cscript //nologo %windir%\system32\slmgr.vbs /rilc %nul% +call :dk_refresh +call :dk_actids if not defined applist ( %eline% echo Activation IDs not found. Aborting... echo: -echo Check this page for help. https://massgrave.dev/troubleshoot +echo Check this page for help. https://%mas%/troubleshoot goto ced_done ) - -:: Check Windows Edition - -set osedition= -for /f "tokens=3 delims=: " %%a in ('DISM /English /Online /Get-CurrentEdition 2^>nul ^| find /i "Current Edition :"') do set "osedition=%%a" - -if "%osedition%"=="" ( -%eline% -DISM /English /Online /Get-CurrentEdition %nul% -cmd /c exit /b !errorlevel! -echo DISM command failed [Error Code - 0x!=ExitCode!] -echo OS Edition was not detected properly. Aborting... -echo: -echo Check this page for help. https://massgrave.dev/troubleshoot -goto ced_done ) +::======================================================================================================================================== + :: Check SKU value set osSKU= -set regSKU= +set slcSKU= set wmiSKU= -for /f "tokens=3 delims=." %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v OSProductPfn 2^>nul') do set "regSKU=%%a" -if %_wmic% EQU 1 for /f "tokens=2 delims==" %%a in ('"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST" 2^>nul') do if not errorlevel 1 set "wmiSKU=%%a" -if %_wmic% EQU 0 for /f "tokens=1" %%a in ('%psc% "([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU" 2^>nul') do if not errorlevel 1 set "wmiSKU=%%a" +if %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo) +set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3); +set d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku +for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set slcSKU=%%s) +if "%slcSKU%"=="0" set slcSKU= +if 1%slcSKU% NEQ +1%slcSKU% set slcSKU= + +if %_wmic% EQU 1 for /f "tokens=2 delims==" %%a in ('"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST" %nul6%') do if not errorlevel 1 set "wmiSKU=%%a" +if %_wmic% EQU 0 for /f "tokens=1" %%a in ('%psc% "([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU" %nul6%') do if not errorlevel 1 set "wmiSKU=%%a" -set osSKU=%wmiSKU% -if not defined osSKU set osSKU=%regSKU% +set osSKU=%slcSKU% +if not defined osSKU set osSKU=%wmiSKU% if not defined osSKU ( %eline% @@ -233,14 +280,56 @@ echo SKU value was not detected properly. Aborting... goto ced_done ) +::======================================================================================================================================== + +:: Check Windows Edition + +set osedition= +set dismedition= +set dismnotworking= + +set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [int], @([String], [int], [int].MakeByRefType(), [String].MakeByRefType()), 1, 3); +set d1=%d1% $editionName = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformation('Kernel-EditionName', 0, [ref]0, [ref]$editionName); $editionName +if %winbuild% GEQ 14393 for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set osedition=%%s) +if "%osedition%"=="0" set osedition= + +if not defined osedition ( +for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul6%') do set "osedition=%%a" +) + +:: Workaround for a Windows bug in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional + +if %osSKU%==164 set osedition=ProfessionalEducation +if %osSKU%==165 set osedition=ProfessionalEducationN + +for /f "tokens=3 delims=: " %%a in ('DISM /English /Online /Get-CurrentEdition %nul6% ^| find /i "Current Edition :"') do set "dismedition=%%a" +if not defined dismedition set dismnotworking=1 + +if defined dismedition if not defined osedition set osedition=%dismedition% + +if not defined osedition ( +%eline% +DISM /English /Online /Get-CurrentEdition %nul% +cmd /c exit /b !errorlevel! +echo DISM command failed [Error Code - 0x!=ExitCode!] +echo OS Edition was not detected properly. Aborting... +echo: +echo Check this page for help. https://%mas%/troubleshoot +goto ced_done +) + +::======================================================================================================================================== + set branch= -for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildBranch 2^>nul') do set "branch=%%b" +for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildBranch %nul6%') do set "branch=%%b" :: Check PowerShell -%psc% $ExecutionContext.SessionState.LanguageMode 2>nul | find /i "Full" 1>nul || ( +%psc% $ExecutionContext.SessionState.LanguageMode %nul2% | find /i "Full" %nul1% || ( %eline% echo PowerShell is not responding properly. Aborting... +echo: +echo Check this page for help. https://%mas%/troubleshoot goto ced_done ) @@ -252,15 +341,22 @@ set _target= set _dtarget= set _ptarget= set _ntarget= +set _wtarget= + +if %winbuild% GEQ 10240 for /f "tokens=4" %%a in ('dism /online /english /Get-TargetEditions ^| findstr /i /c:"Target Edition : "') do (if defined _dtarget (set "_dtarget= !_dtarget! %%a ") else (set "_dtarget= %%a ")) +if %winbuild% LSS 10240 for /f "tokens=4" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':cbsxml\:.*';& ([ScriptBlock]::Create($f[1])) -GetTargetEditions;" ^| findstr /i /c:"Target Edition : "') do (if defined _ptarget (set "_ptarget= !_ptarget! %%a ") else (set "_ptarget= %%a ")) -if %winbuild% GEQ 10240 for /f "tokens=4" %%a in ('dism /online /english /Get-TargetEditions ^| findstr /i /c:"Target Edition : "') do (if defined _dtarget (set "_dtarget=!_dtarget! %%a") else (set "_dtarget=%%a")) -for /f "tokens=4" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':cbsxml\:.*';& ([ScriptBlock]::Create($f[1])) -GetTargetEditions;" ^| findstr /i /c:"Target Edition : "') do (if defined _ptarget (set "_ptarget=!_ptarget! %%a") else (set "_ptarget=%%a")) +if %winbuild% GEQ 10240 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" ( +call :ced_edilist +if /i "%osedition:~0,4%"=="Core" (set "_wtarget= Professional !_wtarget! ") +set "_dtarget= %_dtarget% !_wtarget! " +) ::======================================================================================================================================== -:: Block the change to/from CountrySpecific and CloudEdition editions +:: Block the change to/from CloudEdition editions -for %%# in (99 139 202 203) do if %osSKU%==%%# ( +for %%# in (202 203) do if %osSKU%==%%# ( %eline% echo [%winos% ^| SKU:%osSKU% ^| %winbuild%] echo It's not recommended to change this installed edition to any other. @@ -268,8 +364,8 @@ echo Aborting... goto ced_done ) -for %%# in ( %_dtarget% %_ptarget% ) do ( -echo "!_target!" | find /i " %%# " 1>nul || set "_target=!_target! %%# " +for %%# in ( %_dtarget% %_ptarget% ) do if /i not "%%#"=="%osedition%" ( +echo "!_target!" | find /i " %%# " %nul1% || set "_target= !_target! %%# " ) if defined _target ( @@ -281,6 +377,7 @@ echo %%# | findstr /i "CountrySpecific CloudEdition" %nul% || (set "_ntarget=!_n if not defined _ntarget ( %line% echo: +if defined dismnotworking call :dk_color %Red% "DISM.exe is not responding." call :dk_color %Gray% "Target Edition not found." echo Current Edition [%osedition% ^| %winbuild%] can not be changed to any other Edition. %line% @@ -294,7 +391,6 @@ goto ced_done cls mode 98, 30 set inpt= -set note= set counter=0 set verified=0 set targetedition= @@ -302,21 +398,16 @@ set targetedition= %line% echo: call :dk_color %Gray% "You can change the Edition [%osedition%] [%winbuild%] to one of the following." +if defined dismnotworking ( +call :dk_color %_Yellow% "Note - DISM.exe is not responding." +if /i "%osedition:~0,4%"=="Core" call :dk_color %_Yellow% " - You will see more edition options to choose once its changed to Pro." +) %line% echo: for %%A in (%_ntarget%) do ( set /a counter+=1 -if %winbuild% GEQ 10240 ( -echo "%_ptarget%" | find /i "%%A" 1>nul && ( -set note=1 -call :dk_color2 %_White% "[!counter!] " %Magenta% "%%A" -) || ( -echo [!counter!] %%A -) -) else ( echo [!counter!] %%A -) set targetedition!counter!=%%A ) @@ -324,10 +415,6 @@ set targetedition!counter!=%%A echo: echo [0] %_exitmsg% echo: -if defined note ( -echo Note: CBS Upgrade Method is available for Purple colored editions. -echo: -) call :dk_color %_Green% "Enter option number in keyboard, and press "Enter":" set /p inpt= if "%inpt%"=="" goto cedmenu2 @@ -338,71 +425,26 @@ if %verified%==0 goto cedmenu2 ::======================================================================================================================================== -cls -if %winbuild% GEQ 10240 ( -echo "%_ptarget%" | find /i "%targetedition%" 1>nul && ( -echo "%_dtarget%" | find /i "%targetedition%" 1>nul && ( -echo: -%line% -echo: -if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" ( -echo [1] DISM Method [Recommended] -) else ( -echo [1] Changepk Method [Recommended] -) -echo: -echo [2] CBS Upgrade Method [Alternative] -echo: -echo [0] Go back -%line% -echo: -echo Enter a menu option in the Keyboard: -choice /C:120 /N -set _el=!errorlevel! -if !_el!==3 goto :cedmenu2 -if !_el!==2 goto :cbsmethod -if !_el!==1 REM -) -) -) else ( -goto :cbsmethod -) - -echo "%_ptarget%" | find /i "%targetedition%" 1>nul && ( -echo "%_dtarget%" | find /i "%targetedition%" 1>nul || ( -goto :cbsmethod -) -) - -if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" ( -goto :ced_change_server -) +if %winbuild% LSS 10240 goto :cbsmethod +if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" goto :ced_change_server cls +mode con cols=105 lines=32 + set key= set _chan= -set _changepk=0 +set _dismapi=0 -:: Check if changepk.exe or slmgr.vbs is required for edition upgrade +:: Check if DISM Api or slmgr.vbs is required for edition upgrade if not exist "%SystemRoot%\System32\spp\tokens\skus\%targetedition%\" ( -set _changepk=1 +set _dismapi=1 ) -if /i "%osedition:~0,4%"=="Core" ( -if /i not "%targetedition:~0,4%"=="Core" ( -set _changepk=1 -) -) - -if %_changepk%==1 ( -set "keyflow=Retail Volume:MAK Volume:GVLK OEM:NONSLP OEM:DM" -) else ( set "keyflow=Retail OEM:NONSLP OEM:DM Volume:MAK Volume:GVLK" -) -if not defined key call :ced_targetSKU %targetedition% -if not defined key if defined targetSKU call :ced_windowskey +call :ced_targetSKU %targetedition% +if defined targetSKU call :ced_windowskey if defined key if defined pkeychannel set _chan=%pkeychannel% if not defined key call :changeeditiondata @@ -410,57 +452,26 @@ if not defined key ( %eline% echo [%targetedition% ^| %winbuild%] echo Unable to get product key from pkeyhelper.dll -echo Make sure you are using updated version of the script. -echo https://massgrave.dev +echo: +echo Check this page for help. https://%mas%/troubleshoot goto ced_done ) ::======================================================================================================================================== -%line% - -:: Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires "changepk /productkey" method and restart +:: Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires "changepk /productkey" or DISM Api method and restart :: In other cases, editions can be changed instantly with "slmgr /ipk" cls -if %_changepk%==1 ( -echo "%_chan%" | find /i "OEM" >NUL && ( -%eline% -echo [%osedition%] can not be changed to [%targetedition%] Edition due to lack of non OEM keys. -echo Non-OEM keys are required to change from Core to Non-Core Editions. -goto ced_done -) -) - -:ced_loop - -cls -if %_changepk%==1 ( -for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do ( -for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do ( -if not [%%#]==[] ( -%eline% -echo Internet needs to be disconnected to change edition [%osedition%] to [%targetedition%] -echo Disconnect the Internet and then press any key... -pause >nul -goto ced_loop -) -) -) -) - +%line% echo: -echo Changing the Current Edition [%osedition%] to [%targetedition%] +echo Changing the Current Edition [%osedition%] %winbuild% to [%targetedition%] echo: -if %_changepk%==1 ( -call :dk_color %Magenta% "Notes-" -echo: -echo - You can safely ignore if error appears in the upgrade Window, -echo but in that case you must manually reboot the system. +if %_dismapi%==1 ( +call :dk_color %Blue% "Notes-" echo: echo - Save your work before continue, system will auto restart. -echo - You can connect to Internet after the system restart. echo: echo - You will need to activate with HWID option once the edition is changed. echo: @@ -470,7 +481,7 @@ if !errorlevel!==1 exit /b ::======================================================================================================================================== -if %_changepk%==0 ( +if %_dismapi%==0 ( echo Installing %_chan% Key [%key%] echo: if %_wmic% EQU 1 wmic path SoftwareLicensingService where __CLASS='SoftwareLicensingService' call InstallProductKey ProductKey="%key%" %nul% @@ -488,14 +499,19 @@ echo: call :dk_color %Gray% "Reboot is required to properly change the Edition." ) else ( call :dk_color %Red% "[Unsuccessful] [Error Code: 0x!=ExitCode!]" +echo Check this page for help. https://%mas%/troubleshoot ) ) -if %_changepk%==1 ( +if %_dismapi%==1 ( echo: -echo Applying the command with %_chan% Key -echo start changepk.exe /ProductKey %key% -start changepk.exe /ProductKey %key% +echo Applying the DISM API method with %_chan% Key %key% +echo: +%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':dismapi\:.*';& ([ScriptBlock]::Create($f[1])) %targetedition% %key%;" +timeout /t 3 %nul1% +echo: +call :dk_color %Blue% "Incase of errors, you must restart your system before trying again." +echo Check this page for help. https://%mas%/troubleshoot ) %line% @@ -507,13 +523,12 @@ goto ced_done cls mode con cols=105 lines=32 -%nul% %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" +%psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" echo: -echo Changing the Current Edition [%osedition%] to [%targetedition%] +echo Changing the Current Edition [%osedition%] %winbuild% to [%targetedition%] echo: -call :dk_color %Magenta% "Important - Save your work before continue, system will auto reboot." -if %winbuild% GEQ 17034 if %targetedition%==Professional echo - Enterprise Key will be installed instead of Pro, you can quickly change to Pro later. +call :dk_color %Blue% "Important - Save your work before continue, system will auto reboot." echo: choice /C:01 /N /M "[1] Continue [0] %_exitmsg% : " if %errorlevel%==1 exit /b @@ -524,9 +539,11 @@ echo: if %_stg%==0 (set stage=) else (set stage=-StageCurrent) %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':cbsxml\:.*';& ([ScriptBlock]::Create($f[1])) -SetEdition %targetedition% %stage%;" - echo: +call :dk_color %Blue% "Incase of errors, you must restart your system before trying again." +echo Check this page for help. https://%mas%/troubleshoot %line% + goto ced_done ::======================================================================================================================================== @@ -535,23 +552,23 @@ goto ced_done cls mode con cols=105 lines=32 -%nul% %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" +%psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" set key= -set pkeychannel= +set _chan= set "keyflow=Volume:GVLK Retail Volume:MAK OEM:NONSLP OEM:DM" -call :changeeditionserverdata -if not defined key call :ced_targetSKU %targetedition% -if not defined key if defined targetSKU call :ced_windowskey -if defined key if not defined pkeychannel call :dk_pkeychannel %key% +call :ced_targetSKU %targetedition% +if defined targetSKU call :ced_windowskey +if defined key if defined pkeychannel set _chan=%pkeychannel% +if not defined key call :changeeditiondata if not defined key ( %eline% echo [%targetedition% ^| %winbuild%] echo Unable to get product key from pkeyhelper.dll -echo Make sure you are using updated version of the script. -echo https://massgrave.dev +echo: +echo Check this page for help. https://%mas%/troubleshoot goto ced_done ) @@ -559,13 +576,14 @@ goto ced_done cls echo: -echo Changing the Current Edition [%osedition%] to [%targetedition%] +echo Changing the Current Edition [%osedition%] %winbuild% to [%targetedition%] echo: -echo Applying the command with %pkeychannel% Key +echo Applying the command with %_chan% Key echo DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula -call :dk_color %Magenta% "Make sure to restart the system." +call :dk_color %Blue% "You must restart the system at this stage." +echo Help: https://%mas%/troubleshoot ::======================================================================================================================================== @@ -573,7 +591,7 @@ call :dk_color %Magenta% "Make sure to restart the system." echo: call :dk_color %_Yellow% "Press any key to %_exitmsg%..." -pause >nul +pause %nul1% exit /b ::======================================================================================================================================== @@ -591,18 +609,27 @@ exit /b :dk_actids set applist= -if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path SoftwareLicensingProduct where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f') get ID /VALUE" 2^>nul')" -if %_wmic% EQU 0 set "chkapp=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT ID FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f''').Get()).ID ^| %% {echo ('ID='+$_)}" 2^>nul')" +if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path SoftwareLicensingProduct where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f') get ID /VALUE" %nul6%')" +if %_wmic% EQU 0 set "chkapp=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT ID FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f''').Get()).ID ^| %% {echo ('ID='+$_)}" %nul6%')" %chkapp% do (if defined applist (call set "applist=!applist! %%a") else (call set "applist=%%a")) exit /b +:: Get Edition list + +:ced_edilist + +if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path SoftwareLicensingProduct where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f') get LicenseFamily /VALUE" %nul6%')" +if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f''').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')" +%chkedi% do (call set "_wtarget= !_wtarget! %%a ") +exit /b + :: Check wmic.exe :dk_ckeckwmic set _wmic=0 for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" ( -wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "computersystem" 1>nul && set _wmic=1 +wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i "computersystem" %nul1% && set _wmic=1 ) exit /b @@ -617,8 +644,8 @@ set d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::Brandi set winos= for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set winos=%%s) -echo "%winos%" | find /i "Windows" 1>nul || ( -for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName 2^>nul') do set "winos=%%b" +echo "%winos%" | find /i "Windows" %nul1% || ( +for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName %nul6%') do set "winos=%%b" if %winbuild% GEQ 22000 ( set winos=!winos:Windows 10=Windows 11! ) @@ -944,59 +971,92 @@ Restart-Computer ::======================================================================================================================================== +:: Change edition using DISM API +:: Thanks to Alex (aka may, ave9858) + +:dismapi:[ +param ( + [Parameter()] + [String]$TargetEdition, + + [Parameter()] + [String]$Key +) + +$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1) +$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False) +$TB = $ModuleBuilder.DefineType(0) + +[void]$TB.DefinePInvokeMethod('DismInitialize', 'DismApi.dll', 22, 1, [int], @([int], [IntPtr], [IntPtr]), 1, 3) +[void]$TB.DefinePInvokeMethod('DismOpenSession', 'DismApi.dll', 22, 1, [int], @([String], [IntPtr], [IntPtr], [UInt32].MakeByRefType()), 1, 3) +[void]$TB.DefinePInvokeMethod('_DismSetEdition', 'DismApi.dll', 22, 1, [int], @([UInt32], [String], [String], [IntPtr], [IntPtr], [IntPtr]), 1, 3) +$Dism = $TB.CreateType() + +[void]$Dism::DismInitialize(2, 0, 0) +$Session = 0 +[void]$Dism::DismOpenSession('DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}', 0, 0, [ref]$Session) +if (!$Dism::_DismSetEdition($Session, "$TargetEdition", "$Key", 0, 0, 0)) { + Restart-Computer +} +:dismapi:] + +::======================================================================================================================================== + :: 1st column = Generic Retail/OEM/MAK/GVLK Key :: 2nd column = Key Type :: 3rd column = WMI Edition ID :: 4th column = Version name incase same Edition ID is used in different OS versions with different key :: Separator = _ -:: Key preference is in the following order. Retail > Volume:MAK > Volume:GVLK > OEM:NONSLP > OEM:DM -:: OEM keys are in last because they can't be used in edition change if "changepk /productkey" method is needed instead of "slmgr /ipk" -:: OEM keys are listed here because we don't have other keys for that edition +:: For Windows 10/11 editions, HWID key is listed where ever possible, in Server versions, KMS key is listed where ever possible. +:: Only RS3 and older version Generic keys are stored here, later ones are extracted from the pkeyhelper.dll itself :changeeditiondata +if %winbuild% GTR 17763 exit /b +if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*CorEdition~*.mum" (set Cor=Cor) else (set Cor=) + set h= for %%# in ( -44N%h%YX-TK%h%R9D-CCM2%h%D-V6%h%B8F-HQ%h%WWR__Volume:MAK_Enterprise -D6R%h%D9-D4%h%N8T-RT9Q%h%X-YW%h%6YT-FC%h%WWJ______Retail_Starter -3V6%h%Q6-NQ%h%XCX-V8YX%h%R-9Q%h%CYV-QP%h%FCT__Volume:MAK_EnterpriseN -3NF%h%XW-2T%h%27M-2BDW%h%6-4G%h%HRV-68%h%XRX______Retail_StarterN -VK7%h%JG-NP%h%HTM-C97J%h%M-9M%h%PGT-3V%h%66T______Retail_Professional -2B8%h%7N-8K%h%FHP-DKV6%h%R-Y2%h%C8J-PK%h%CKT______Retail_ProfessionalN -4CP%h%RK-NM%h%3K3-X6XX%h%Q-RX%h%X86-WX%h%CHW______Retail_CoreN -N24%h%34-X9%h%D7W-8PF6%h%X-8D%h%V9T-8T%h%YMD______Retail_CoreCountrySpecific -BT7%h%9Q-G7%h%N6G-PGBY%h%W-4Y%h%WX6-6F%h%4BT______Retail_CoreSingleLanguage -YTM%h%G3-N6%h%DKC-DKB7%h%7-7M%h%9GH-8H%h%VX7______Retail_Core -XKC%h%NC-J2%h%6Q9-KFHD%h%2-FK%h%THY-KD%h%72Y__OEM:NONSLP_PPIPro -YNM%h%GQ-8R%h%YV3-4PGQ%h%3-C8%h%XTP-7C%h%FBY______Retail_Education -84N%h%GF-MH%h%BT6-FXBX%h%8-QW%h%JK7-DR%h%R8H______Retail_EducationN -KCN%h%VH-YK%h%WX8-GJJB%h%9-H9%h%FDT-6F%h%7W2__Volume:MAK_EnterpriseS_VB -VBX%h%36-N7%h%DDY-M9H6%h%2-83%h%BMJ-CP%h%R42__Volume:MAK_EnterpriseS_RS5 -PN3%h%KR-JX%h%M7T-46HM%h%4-MC%h%QGK-7X%h%PJQ__Volume:MAK_EnterpriseS_RS1 -DVW%h%KN-3G%h%CMV-Q2XF%h%4-DD%h%PGM-VQ%h%WWY__Volume:MAK_EnterpriseS_TH -RQF%h%NW-9T%h%PM3-JQ73%h%T-QV%h%4VQ-DV%h%9PT__Volume:MAK_EnterpriseSN_VB -M33%h%WV-NH%h%Y3C-R7FP%h%M-BQ%h%GPT-23%h%9PG__Volume:MAK_EnterpriseSN_RS5 -2DB%h%W3-N2%h%PJG-MVHW%h%3-G7%h%TDK-9H%h%KR4__Volume:MAK_EnterpriseSN_RS1 -NTX%h%6B-BR%h%YC2-K678%h%6-F6%h%MVQ-M7%h%V2X__Volume:MAK_EnterpriseSN_TH -G3K%h%NM-CH%h%G6T-R36X%h%3-9Q%h%DG6-8M%h%8K9______Retail_ProfessionalSingleLanguage -HNG%h%CC-Y3%h%8KG-QVK8%h%D-WM%h%WRK-X8%h%6VK______Retail_ProfessionalCountrySpecific -DXG%h%7C-N3%h%6C4-C4HT%h%G-X4%h%T3X-2Y%h%V77______Retail_ProfessionalWorkstation -WYP%h%NQ-8C%h%467-V2W6%h%J-TX%h%4WX-WT%h%2RQ______Retail_ProfessionalWorkstationN -8PT%h%T6-RN%h%W4C-6V7J%h%2-C2%h%D3X-MH%h%BPB______Retail_ProfessionalEducation -GJT%h%YN-HD%h%MQY-FRR7%h%6-HV%h%GC7-QP%h%F8P______Retail_ProfessionalEducationN -C4N%h%TJ-CX%h%6Q2-VXDM%h%R-XV%h%KGM-F9%h%DJC__Volume:MAK_EnterpriseG -46P%h%N6-R9%h%BK9-CVHK%h%B-HW%h%Q9V-MB%h%JY8__Volume:MAK_EnterpriseGN -NJC%h%F7-PW%h%8QT-3324%h%D-68%h%8JX-2Y%h%V66______Retail_ServerRdsh -V3W%h%VW-N2%h%PV2-CGWC%h%3-34%h%QGF-VM%h%J2C______Retail_Cloud -NH9%h%J3-68%h%WK7-6FB9%h%3-4K%h%3DF-DJ%h%4F6______Retail_CloudN -2HN%h%6V-HG%h%TM8-6C97%h%C-RK%h%67V-JQ%h%PFD______Retail_CloudE -XQQ%h%YW-NF%h%FMW-XJPB%h%H-K8%h%732-CK%h%FFD______OEM:DM_IoTEnterprise -QPM%h%6N-7J%h%2WJ-P88H%h%H-P3%h%YRH-YY%h%74H__OEM:NONSLP_IoTEnterpriseS_VB -KBN%h%8V-HF%h%GQ4-MGXV%h%D-34%h%7P6-PD%h%QGT_Volume:GVLK_IoTEnterpriseS_NI -K9V%h%KN-3B%h%GWV-Y624%h%W-MC%h%RMQ-BH%h%DCD______Retail_CloudEditionN -KY7%h%PN-VR%h%6RX-83W6%h%Y-6D%h%DYQ-T6%h%R4W______Retail_CloudEdition -MPB%h%3G-XN%h%BR7-CC43%h%M-FG%h%64B-F9%h%GBK______Retail_IoTEnterpriseSK +XGV%h%PP-NM%h%H47-7TT%h%HJ-W%h%3FW7-8HV%h%2C__OEM:NONSLP_Enterprise +D6R%h%D9-D4%h%N8T-RT9%h%QX-Y%h%W6YT-FCW%h%WJ______Retail_Starter +3V6%h%Q6-NQ%h%XCX-V8Y%h%XR-9%h%QCYV-QPF%h%CT__Volume:MAK_EnterpriseN +3NF%h%XW-2T%h%27M-2BD%h%W6-4%h%GHRV-68X%h%RX______Retail_StarterN +VK7%h%JG-NP%h%HTM-C97%h%JM-9%h%MPGT-3V6%h%6T______Retail_Professional +2B8%h%7N-8K%h%FHP-DKV%h%6R-Y%h%2C8J-PKC%h%KT______Retail_ProfessionalN +4CP%h%RK-NM%h%3K3-X6X%h%XQ-R%h%XX86-WXC%h%HW______Retail_CoreN +N24%h%34-X9%h%D7W-8PF%h%6X-8%h%DV9T-8TY%h%MD______Retail_CoreCountrySpecific +BT7%h%9Q-G7%h%N6G-PGB%h%YW-4%h%YWX6-6F4%h%BT______Retail_CoreSingleLanguage +YTM%h%G3-N6%h%DKC-DKB%h%77-7%h%M9GH-8HV%h%X7______Retail_Core +XKC%h%NC-J2%h%6Q9-KFH%h%D2-F%h%KTHY-KD7%h%2Y__OEM:NONSLP_PPIPro +YNM%h%GQ-8R%h%YV3-4PG%h%Q3-C%h%8XTP-7CF%h%BY______Retail_Education +84N%h%GF-MH%h%BT6-FXB%h%X8-Q%h%WJK7-DRR%h%8H______Retail_EducationN +NK9%h%6Y-D9%h%CD8-W44%h%CQ-R%h%8YTK-DYJ%h%WX__OEM:NONSLP_EnterpriseS_RS1 +FWN%h%7H-PF%h%93Q-4GG%h%P8-M%h%8RF3-MDW%h%WW__OEM:NONSLP_EnterpriseS_TH +2DB%h%W3-N2%h%PJG-MVH%h%W3-G%h%7TDK-9HK%h%R4__Volume:MAK_EnterpriseSN_RS1 +NTX%h%6B-BR%h%YC2-K67%h%86-F%h%6MVQ-M7V%h%2X__Volume:MAK_EnterpriseSN_TH +G3K%h%NM-CH%h%G6T-R36%h%X3-9%h%QDG6-8M8%h%K9______Retail_ProfessionalSingleLanguage +HNG%h%CC-Y3%h%8KG-QVK%h%8D-W%h%MWRK-X86%h%VK______Retail_ProfessionalCountrySpecific +DXG%h%7C-N3%h%6C4-C4H%h%TG-X%h%4T3X-2YV%h%77______Retail_ProfessionalWorkstation +WYP%h%NQ-8C%h%467-V2W%h%6J-T%h%X4WX-WT2%h%RQ______Retail_ProfessionalWorkstationN +8PT%h%T6-RN%h%W4C-6V7%h%J2-C%h%2D3X-MHB%h%PB______Retail_ProfessionalEducation +GJT%h%YN-HD%h%MQY-FRR%h%76-H%h%VGC7-QPF%h%8P______Retail_ProfessionalEducationN +C4N%h%TJ-CX%h%6Q2-VXD%h%MR-X%h%VKGM-F9D%h%JC__Volume:MAK_EnterpriseG +46P%h%N6-R9%h%BK9-CVH%h%KB-H%h%WQ9V-MBJ%h%Y8__Volume:MAK_EnterpriseGN +NJC%h%F7-PW%h%8QT-332%h%4D-6%h%88JX-2YV%h%66______Retail_ServerRdsh +V3W%h%VW-N2%h%PV2-CGW%h%C3-3%h%4QGF-VMJ%h%2C______Retail_Cloud +NH9%h%J3-68%h%WK7-6FB%h%93-4%h%K3DF-DJ4%h%F6______Retail_CloudN +2HN%h%6V-HG%h%TM8-6C9%h%7C-R%h%K67V-JQP%h%FD______Retail_CloudE +WC2%h%BQ-8N%h%RM3-FDD%h%YY-2%h%BFGV-KHK%h%QY_Volume:GVLK_ServerStandard%Cor%_RS1 +CB7%h%KF-BW%h%N84-R7R%h%2Y-7%h%93K2-8XD%h%DG_Volume:GVLK_ServerDatacenter%Cor%_RS1 +JCK%h%RF-N3%h%7P4-C2D%h%82-9%h%YXRT-4M6%h%3B_Volume:GVLK_ServerSolution_RS1 +QN4%h%C6-GB%h%JD2-FB4%h%22-G%h%HWJK-GJG%h%2R_Volume:GVLK_ServerCloudStorage_RS1 +VP3%h%4G-4N%h%PPG-79J%h%TQ-8%h%64T4-R3M%h%QX_Volume:GVLK_ServerAzureCor_RS1 +9JQ%h%NQ-V8%h%HQ6-PKB%h%8H-G%h%GHRY-R62%h%H6______Retail_ServerAzureNano_RS1 +VN8%h%D3-PR%h%82H-DB6%h%BJ-J%h%9P4M-92F%h%6J______Retail_ServerStorageStandard_RS1 +48T%h%QX-NV%h%K3R-D8Q%h%R3-G%h%THHM-8FH%h%XC______Retail_ServerStorageWorkgroup_RS1 +2HX%h%DN-KR%h%XHB-GPY%h%C7-Y%h%CKFJ-7FV%h%DG_Volume:GVLK_ServerDatacenterACor_RS3 +PTX%h%N8-JF%h%HJM-4WC%h%78-M%h%PCBR-9W4%h%KR_Volume:GVLK_ServerStandardACor_RS3 ) do ( for /f "tokens=1-4 delims=_" %%A in ("%%#") do if /i %targetedition%==%%C ( @@ -1005,7 +1065,7 @@ set 4th=%%D if not defined 4th ( set "key=%%A" & set "_chan=%%B" ) else ( -echo "%branch%" | find "%%D" 1>nul && (set "key=%%A" & set "_chan=%%B") +echo "%branch%" | find /i "%%D" %nul1% && (set "key=%%A" & set "_chan=%%B") ) ) ) @@ -1013,30 +1073,4 @@ echo "%branch%" | find "%%D" 1>nul && (set "key=%%A" & set "_chan=%%B") exit /b ::======================================================================================================================================== - -:changeeditionserverdata - -if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*CorEdition~*.mum" (set Cor=Cor) else (set Cor=) - -:: Only RS3 and older version keys (GVLK/Generic Retail) are stored here, later ones are extracted from the system itself - -set h= -for %%# in ( -WC2%h%BQ-8N%h%RM3-FDD%h%YY-2B%h%FGV-KHK%h%QY_RS1_ServerStandard%Cor% -CB7%h%KF-BW%h%N84-R7R%h%2Y-79%h%3K2-8XD%h%DG_RS1_ServerDatacenter%Cor% -JCK%h%RF-N3%h%7P4-C2D%h%82-9Y%h%XRT-4M6%h%3B_RS1_ServerSolution -QN4%h%C6-GB%h%JD2-FB4%h%22-GH%h%WJK-GJG%h%2R_RS1_ServerCloudStorage -VP3%h%4G-4N%h%PPG-79J%h%TQ-86%h%4T4-R3M%h%QX_RS1_ServerAzureCor -9JQ%h%NQ-V8%h%HQ6-PKB%h%8H-GG%h%HRY-R62%h%H6_RS1_ServerAzureNano -VN8%h%D3-PR%h%82H-DB6%h%BJ-J9%h%P4M-92F%h%6J_RS1_ServerStorageStandard -48T%h%QX-NV%h%K3R-D8Q%h%R3-GT%h%HHM-8FH%h%XC_RS1_ServerStorageWorkgroup -2HX%h%DN-KR%h%XHB-GPY%h%C7-YC%h%KFJ-7FV%h%DG_RS3_ServerDatacenterACor -PTX%h%N8-JF%h%HJM-4WC%h%78-MP%h%CBR-9W4%h%KR_RS3_ServerStandardACor -) do ( -for /f "tokens=1-3 delims=_" %%A in ("%%#") do if /i %targetedition%==%%C ( -echo "%branch%" | find /i "%%B" 1>nul && (set "key=%%A") -) -) -exit /b - -::======================================================================================================================================== \ No newline at end of file +:: Leave empty line below -- cgit v1.2.3