VS Code setup cannot replace its own files on Windows
Your error
An error occurred while trying to replace the existing file: DeleteFile failed; code 5. Access is denied.2 more lines it can showFix it fast
Most common cause, 1 of 3A Code.exe process is still running in the background
Save your work, end every Code.exe together with its child processes, then run the update or the installer again.
taskkill /im Code.exe /t /fShort answer
DeleteFile failed; code 5. Access is denied means VS Code's Windows installer could not remove an old file. A Code.exe process still running, security software holding the file, or a System setup updated without admin rights are the usual causes. End every Code.exe, restart if needed, then rerun the right installer. Applies to VS Code 1.147.
Which cause do you have?
With every VS Code window closed, list any Code.exe still alive and check which kind of install you have. A process in the list points to cause 1; no process but a Program Files install points to cause 3.
tasklist /fi "IMAGENAME eq Code.exe"
dir "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe"
dir "C:\Program Files\Microsoft VS Code\Code.exe"Then find the line you see in this list and open its fix:
- 1A Code.exe process is still running in the background
tasklist still shows one or more Code.exe lines after you closed every window - 2Antivirus or another security tool has the file open
No Code.exe is running, the error still appears, and the machine runs company security software or a third-party antivirus - 3A System setup in Program Files is updated without admin rights
Code.exe lives under C:\Program Files\Microsoft VS Code and the installer or update was started from a normal, non-elevated account
What does the error look like?
An error occurred while trying to replace the existing file: DeleteFile failed; code 5. Access is denied.Failed to install Visual Studio Code update.Updates may fail due to anti-virus software and/or runaway processes. Please try restarting your machine before attempting to update again.
Cause 1 of 3
A Code.exe process is still running in the background
You seetasklist still shows one or more Code.exe lines after you closed every window
Check
Code 5 is the Windows error ERROR_ACCESS_DENIED. Before it swaps files, VS Code's updater looks for running VS Code processes and tries to stop them. A leftover process it cannot stop keeps the old files in use, so the delete is refused.
tasklist /fi "IMAGENAME eq Code.exe"Fix
Save your work, end every Code.exe together with its child processes, then run the update or the installer again.
taskkill /im Code.exe /t /fVerify
tasklist prints no Code.exe line, setup finishes, and Help > About shows the new version.
code --versionConfirmed by raw.githubusercontent.com
Cause 2 of 3
Antivirus or another security tool has the file open
You seeNo Code.exe is running, the error still appears, and the machine runs company security software or a third-party antivirus
Check
A VS Code maintainer tied this exact failure to antivirus or similar software keeping a handle on Code.exe or other core files. The updater's own error box names anti-virus software and runaway processes as the usual reasons.
dir %TEMP%\vscode-inno-updater-*.logFix
Restart Windows and try the update again, as the updater message itself advises. If background updates keep failing on this machine, switch them off with the setting a maintainer gave as the workaround.
// settings.json (File > Preferences > Settings, then Open Settings (JSON))
"update.enableWindowsBackgroundUpdates": falseVerify
The next update completes without the DeleteFile dialog, and the newest updater log ends without an error.
code --versionConfirmed by github.com
Cause 3 of 3
A System setup in Program Files is updated without admin rights
You seeCode.exe lives under C:\Program Files\Microsoft VS Code and the installer or update was started from a normal, non-elevated account
Check
Microsoft's install guide says the System setup needs administrator permissions and that in-product updates also require elevation. The User setup installs under %LOCALAPPDATA% and needs neither.
dir "C:\Program Files\Microsoft VS Code\Code.exe"Fix
Run the System setup installer with Run as administrator. If you do not have admin rights, use the User setup for your own account instead, which Microsoft recommends for most people.
# System setup: right-click the installer > Run as administrator
# User setup (no admin rights needed), per Microsoft's guide:
VSCodeUserSetup-{version}.exeVerify
Setup completes, and code --version prints the new release in a freshly opened terminal.
code --versionConfirmed by code.visualstudio.com
How do I stop it coming back?
- Close every VS Code window, including remote and tunnel sessions, before you accept an update prompt.
- On a machine you share or do not administer, keep one User setup install only, so updates never need elevation.
- Ask the team that runs endpoint security to allow the VS Code install folder if updates fail on every release.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.