How to fix «Access is denied» on `wsl --install`?

01

Step 1

takeown /f "C:\Program Files" /r /d y
icacls "C:\Program Files" /remove "NULL SID" /t
icacls "C:\Program Files" /grant:r dmitry:F /t

takeown /f "C:\ProgramData" /r /d y
icacls "C:\ProgramData" /remove "NULL SID" /t
icacls "C:\ProgramData" /grant:r dmitry:F /t

Step 2

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

learn.microsoft.com/en-us/windows/wsl/install-manual#step-1---enable-the-windows-subsystem-for-linux

Step 3

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

learn.microsoft.com/en-us/windows/wsl/install-manual#step-3---enable-virtual-machine-feature

Step 4

Reboot.

Step 5

learn.microsoft.com/en-us/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package

Step 6

wsl --set-default-version 2

03
learn.microsoft.com/en-us/windows/wsl/install-manual#step-5---set-wsl-2-as-your-default-version