Access is denied when use del /f in windows 10 64bit Access is denied when use del /f in windows 10 64bit windows windows

Access is denied when use del /f in windows 10 64bit


There are several methods to remove such a file:

1. Process Explorer if the file is in use:
You can use ProcessExplorer from Windows Sysinternals to identifiy which program locks the file. Download and start ProcessExplorer and go to Find|Find Handle or DLL... Ctrl+F and enter the name of the locked file: 1.mp3.

ProcessExplorer will show you the process that is responsible for the lock because of accessing the file. If you've got the proccess kill that one and delete the file.

Example with MS Word accessing a file called LockedFile.docx:
ProcessExplorerExample


2. Safe mode boot:
Another possibility is to boot into safe mode. In pre Windows 8 era this was done by pressing F8 before Windows boots.
In Windows 8 and higher you can press Shift+F8 before Windows boots or more easily you can hold Shift and click Restart in the login screen or even in Windows. If this was too short, look here how to get into safe mode.

Once you're in the safe mode you can try again deleting that file.


3. Remove file on Windows boot via PendingFileRenameOperations:
With PendingFileRenameOperations you can rename and even delete a file on Windows boot procedure when nothing else can access and block that file.PendingFileRenameOperations will be entered in the Windows registry and consists of pairs of file paths.

You can do it manually as described below or again with a Windows Sysinternals program called MoveFile. Download that program and use it in a console window (Start -> Run or Windows-Key+R, type cmd and press ENTER).
Type movefile foo.exe "" to delete a file on reboot.

Manual method via registry:
The 1st path is the file to be renamed.
The 2nd path is the new file path.If the 2nd path is empty (0x0000) the file get's removed.

  1. Start -> Run or Windows-Key+R
  2. Type in regedit, and press ENTER
  3. Goto HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
  4. Create a new Multi-String value: PendingFileRenameOperations
  5. Enter \??\filepath as the data (e.g. \??\C:\Users\xyz\Desktop\foo.exe)
  6. Press OK
  7. Right-click on the key, click Modify Binary Data
  8. At the end of the hex string, add 0000 (4 zeros which represent an empty string)
  9. Press OK
  10. Restart your computer


Lean and mean batch-file only alternatives for PendingFileRenameOperations:
~ Scripts will add an entry to right-click -- "SendTo" menu
~ Accepting a single parameter, either File or Folder
~ Confirmation prompt ([Cancel] to Clear previous entries)
~ Basic idiot proofing (don't process %Windir% for example)

Rename_On_Boot.bat

goto="Batch" /* Rename_On_Boot by AveYo v1:RenOnBootset "input=%*" & call set "input=%%input:?=%%"                            &rem line below adds entry to right-click -- "SendTo" menuif /i "_%~dp0"=="_%APPDATA%\Microsoft\Windows\SendTo\" (set .=) else copy /y "%~f0" "%APPDATA%\Microsoft\Windows\SendTo\" >nul 2>nulif "_%1"=="_" color 4f & echo   ERROR! No input provided & ping -n 6 localhost >nul & exit /bfor %%# in ("C:\" "C:\Boot" "C:\Recovery" "%WINDIR%" "%WINDIR%\system32" "%ProgramData%" "%ProgramFiles%" "%USERPROFILE%") do ( if /i "_%input%"=="_%%~#" color 4f & echo   ERROR! %%# is not safe to delete & ping -n 6 localhost >nul & exit /b)color 0B & echo   Please wait, folders might take a while .. & call cscript /nologo /e:JScript "%~f0" RenOnBoot "%input%" & exit /b:RenOnBoot_Run_As_Admincolor 4f & echo   Asking permission to run as Admin.. & call cscript /nologo /e:JScript "%~f0" RunAsAdmin "%~f1???" & exit /b:"Batch"@echo off & setlocal disabledelayedexpansion & mode 96,4 & echo. & title %~nx0 by AveYo & if not exist "%~f1" goto :RenOnBootreg query HKEY_USERS\S-1-5-20\Environment /v temp 1>nul 2>nul && goto :RenOnBoot || goto :RenOnBoot_Run_As_Admin:"JScript" */function RenOnBoot(f){  var HKLM=0x80000002, k='SYSTEM\\CurrentControlSet\\Control\\Session Manager', v='PendingFileRenameOperations';  var reg=GetObject('winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv'), ws=WSH.CreateObject('WScript.Shell');    var confirmation=ws.Popup(" Rename on next boot? [OK]\n Clear previous entries? [Cancel]\n\n "+f,0,'Rename_On_Boot by AveYo',33);  if (confirmation == 2) { reg.DeleteValue(HKLM, k, v); WSH.quit(); } // Clear existing entries on Cancel press and quit script  var mtd=reg.Methods_('GetMultiStringValue').InParameters.SpawnInstance_(); mtd.hDefKey=HKLM; mtd.sSubKeyName=k; mtd.sValueName=v;  var query=reg.ExecMethod_('GetMultiStringValue', mtd), regvalue=(!query.ReturnValue) ? query.SValue.toArray():[,], entries=[];  var fso=new ActiveXObject('Scripting.FileSystemObject'), fn=fso.GetAbsolutePathName(f);  entries.push('\\??\\'+fn,'\\??\\'+fn+'.ren');  reg.CreateKey(HKLM, k); reg.SetMultiStringValue(HKLM, k, v, entries.concat(regvalue));}if (WSH.Arguments.length>=2 && WSH.Arguments(0)=='RenOnBoot') RenOnBoot(WSH.Arguments(1));function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName, WSH.Arguments(1));//

Delete_On_Boot.bat

goto="Batch" /* Delete_On_Boot by AveYo v1:DelOnBootset "input=%*" & call set "input=%%input:?=%%"                            &rem line below adds entry to right-click -- "SendTo" menuif /i "_%~dp0"=="_%APPDATA%\Microsoft\Windows\SendTo\" (set .=) else copy /y "%~f0" "%APPDATA%\Microsoft\Windows\SendTo\" >nul 2>nulif "_%1"=="_" color 4f & echo   ERROR! No input provided & ping -n 6 localhost >nul & exit /bfor %%# in ("C:\" "C:\Boot" "C:\Recovery" "%WINDIR%" "%WINDIR%\system32" "%ProgramData%" "%ProgramFiles%" "%USERPROFILE%") do ( if /i "_%input%"=="_%%~#" color 4f & echo   ERROR! %%# is not safe to delete & ping -n 6 localhost >nul & exit /b)color 0B & echo   Please wait, folders might take a while .. & call cscript /nologo /e:JScript "%~f0" DelOnBoot "%input%" & exit /b:DelOnBoot_Run_As_Admincolor 4f & echo   Asking permission to run as Admin.. & call cscript /nologo /e:JScript "%~f0" RunAsAdmin "%~f1???" & exit /b:"Batch"@echo off & setlocal disabledelayedexpansion & mode 96,4 & echo. & title %~nx0 by AveYo & if not exist "%~f1" goto :DelOnBootreg query HKEY_USERS\S-1-5-20\Environment /v temp 1>nul 2>nul && goto :DelOnBoot || goto :DelOnBoot_Run_As_Admin:"JScript" */function DelOnBoot(f){  ListDir=function(src, _root,_list) {    _root=_root || src, _list=_list || [];    var root=fso.GetFolder(src), files=new Enumerator(root.Files), dirs=new Enumerator(root.SubFolders);    while (!files.atEnd()) { _list.push(files.item()); files.moveNext(); }    while (!dirs.atEnd()) { _list=ListDir(dirs.item().path, _root,_list); _list.push(dirs.item()); dirs.moveNext(); }    return _list;  };  var HKLM=0x80000002, k='SYSTEM\\CurrentControlSet\\Control\\Session Manager', v='PendingFileRenameOperations';  var reg=GetObject('winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv'), ws=WSH.CreateObject('WScript.Shell');    var confirmation=ws.Popup(" Delete on next boot? [OK]\n Clear previous entries? [Cancel]\n\n "+f,0,'Delete_On_Boot by AveYo',33);  if (confirmation == 2) { reg.DeleteValue(HKLM, k, v); WSH.quit(); } // Clear existing entries on Cancel press and quit script  var mtd=reg.Methods_('GetMultiStringValue').InParameters.SpawnInstance_(); mtd.hDefKey=HKLM; mtd.sSubKeyName=k; mtd.sValueName=v;  var query=reg.ExecMethod_('GetMultiStringValue', mtd), regvalue=(!query.ReturnValue) ? query.SValue.toArray():[,], entries=[];  var fso=new ActiveXObject('Scripting.FileSystemObject'), fn=fso.GetAbsolutePathName(f);  if (fso.FolderExists(fn)) { var list=ListDir(fn); for (var i in list) entries.push('\\??\\'+list[i],''); }  entries.push('\\??\\'+fn,'');  reg.CreateKey(HKLM, k); reg.SetMultiStringValue(HKLM, k, v, entries.concat(regvalue));}if (WSH.Arguments.length>=2 && WSH.Arguments(0)=='DelOnBoot') DelOnBoot(WSH.Arguments(1));function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName, WSH.Arguments(1));//