Bison Infosolutions Knowledgebase
Protect your Lenovo Server
Contact WhatsApp

How to Force Delete Locked “Users” Folder on Windows Using Safe Mode, Long Path Commands, and Registry Hive Unloading

Windows systems sometimes refuse to delete folders even when the user has full administrator rights. This commonly happens with copied or migrated Users folders stored on secondary drives. The issue becomes more complex when files like NTUSER.DAT remain locked by the operating system, or when deeply nested folders exceed the Windows MAX_PATH limitation.

This article explains the technical reasons behind the issue and provides multiple advanced methods to safely remove undeletable folders using Command Prompt, PowerShell, Safe Mode, registry hive unloading, and long-path deletion techniques.


Understanding the Problem

When attempting to delete a copied Windows profile folder such as:

D:\Users

users may encounter errors like:

  • Access Denied
  • File in Use
  • The process cannot access the file because it is being used by another process
  • Directory name is too long

The primary causes are:

  1. Locked Registry Hive (NTUSER.DAT)
  2. Ownership and permission restrictions
  3. Windows Explorer file locks
  4. Long path limitations exceeding 260 characters
  5. Registry transaction log files
  6. Mounted user profile hives under HKEY_USERS


What is NTUSER.DAT?

NTUSER.DAT is a Windows user registry hive file stored inside each user profile.

Example:

D:\Users\Administrator\NTUSER.DAT

This file contains:

  • User-specific registry settings
  • Desktop preferences
  • Application settings
  • Environment configurations

When Windows loads a user profile, this file is mounted into the registry under:

HKEY_USERS

As long as the hive remains mounted, Windows locks the file and prevents deletion.


Common Error Messages

Typical deletion failures include:

The process cannot access the file because it is being used by another process.
You require permission from Administrator.
The directory name is too long.


Step 1 — Take Ownership of the Folder

Open Command Prompt as Administrator and run:

takeown /f "D:\Users" /r /d y

Grant full permissions:

icacls "D:\Users" /grant administrators:F /t

Remove hidden/system attributes:

attrib -h -r -s "D:\Users" /s /d

These commands ensure the administrator account has complete access to all files and subfolders.


Step 2 — Handling Long Path Errors

Modern Windows versions still struggle with extremely deep folder structures.

Example problematic path:

D:\Users\ayush\Downloads\New folder\New folder (2)\New folder (4)\...

To bypass Windows MAX_PATH limitations, use the special long-path syntax:

\\?\

Delete command:

rd /s /q "\\?\D:\Users"

This instructs Windows to bypass normal path parsing and process the full absolute path directly.


Step 3 — Why Killing Explorer.exe Causes a Blank Screen

Many users terminate Explorer to release file locks:

taskkill /f /im explorer.exe

However, explorer.exe controls:

  • Desktop
  • Taskbar
  • Start menu
  • File Explorer UI

In Remote Desktop (RDP) sessions, killing Explorer removes the entire graphical shell, resulting in a black or blank screen.

To restore it:

start explorer.exe

or from Task Manager:

File → Run new task → explorer.exe


Step 4 — Unloading the Mounted Registry Hive

Check loaded registry hives:

reg query HKU

You may see entries like:

HKEY_USERS\S-1-5-21-xxxxxxxxxx

Unload non-system hives:

reg unload "HKU\S-1-5-21-XXXXXXXX-1001"

Do NOT unload:

  • .DEFAULT
  • S-1-5-18
  • S-1-5-19
  • S-1-5-20

After unloading:

del /f /q /a "\\?\D:\Users\Administrator\NTUSER*"

Then remove the directory:

rd /s /q "\\?\D:\Users"


Step 5 — Using Safe Mode (Most Reliable Method)

If files remain locked, Safe Mode is the best solution because Windows loads minimal services and does not mount inactive user profile hives.

Enable Safe Mode

Run:

msconfig

Go to:

  • Boot
  • Safe Boot
  • Minimal

Restart the computer.

In Safe Mode, run:

rd /s /q "\\?\D:\Users"

This method usually succeeds instantly.


Step 6 — Using PowerShell Force Deletion

PowerShell provides an alternative deletion method:

Remove-Item "\\?\D:\Users" -Recurse -Force

Delete only the Administrator profile:

Remove-Item "\\?\D:\Users\Administrator" -Recurse -Force


Step 7 — Using Robocopy Mirror Cleanup

A lesser-known but powerful trick uses robocopy to mirror an empty directory over the problematic folder.

Create empty folder:

mkdir C:\Empty

Mirror empty structure:

robocopy /MIR C:\Empty "D:\Users"

Then delete:

rd /s /q "\\?\D:\Users"

This clears many nested files and invalid paths automatically.


Step 8 — Registry Transaction Files

Windows registry hives also create transaction logs:

NTUSER.DAT.LOG1
NTUSER.DAT.LOG2
*.regtrans-ms
*.TM.blf

These files support registry recovery and consistency.

Safe Mode usually unlocks them automatically.


Best Practices Before Deletion

Before deleting any copied Windows profile folder:

  1. Ensure it is not the active user profile
  2. Verify no applications are using the folder
  3. Create backups if needed
  4. Use Safe Mode for maximum reliability
  5. Avoid killing Explorer during active RDP sessions
  6. Use long-path syntax for deep folders


Conclusion

Deleting stubborn Windows profile folders requires understanding how Windows manages registry hives, file locks, and path limitations.

The most effective combination is:

  • Ownership takeover
  • Long-path deletion (\\?\)
  • Registry hive unloading
  • Safe Mode cleanup

Using these techniques allows administrators to safely remove undeletable folders such as copied Users directories from secondary drives without reinstalling Windows or using third-party utilities.


#windows #windows11 #windows10 #windowsserver #powershell #cmd #administrator #systemadmin #itadmin #troubleshooting #ntuserdat #registry #safemode #rdp #explorerexe #windowsrepair #techsupport #windowscommands #commandprompt #filesystem #permissions #accessdenied #longpath #regedit #robocopy #takeown #icacls #profilecleanup #windowsfix #windowsguide #itengineer #serveradmin #windowsmaintenance #ithelpdesk #desktopsupport #powershellscript #advancedwindows #windowssecurity #datrecovery #systemrepair #computerrepair #networkadmin #windowsfilesystem #technicalarticle #windowsprofile #registryhive #fileinuse #admincommands #windowstips #windowstroubleshooting


windows folder delete ntuser.dat delete delete locked folder force delete windows folder delete users folder windows remove ntuser.dat windows long path delete rd s q command powershell remove item explorer.exe taskkill registry hive unload hke
Sponsored