Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

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 show

Fix it fast

Most common cause, 1 of 3

A 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.

Fix
taskkill /im Code.exe /t /f
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to VS Code 1.147.0 (Windows User and System setup), Windows 10 and 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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:

  1. 1A Code.exe process is still running in the backgroundtasklist still shows one or more Code.exe lines after you closed every window
  2. 2Antivirus or another security tool has the file openNo Code.exe is running, the error still appears, and the machine runs company security software or a third-party antivirus
  3. 3A System setup in Program Files is updated without admin rightsCode.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.

Check
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.

Fix
taskkill /im Code.exe /t /f

Verify

tasklist prints no Code.exe line, setup finishes, and Help > About shows the new version.

Verify
code --version

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Check
dir %TEMP%\vscode-inno-updater-*.log

Fix

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.

Fix
// settings.json (File > Preferences > Settings, then Open Settings (JSON))
"update.enableWindowsBackgroundUpdates": false

Verify

The next update completes without the DeleteFile dialog, and the newest updater log ends without an error.

Verify
code --version

Confirmed by github.com

Did this fix it?

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.

Check
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.

Fix
# System setup: right-click the installer > Run as administrator
# User setup (no admin rights needed), per Microsoft's guide:
VSCodeUserSetup-{version}.exe

Verify

Setup completes, and code --version prints the new release in a freshly opened terminal.

Verify
code --version

Confirmed by code.visualstudio.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.