RI Study Post Blog Editor

Fixing “Access is Denied (OS Error 5)” in Visual Studio Code on Windows

Fixing “Access is Denied (OS Error 5)” in Visual Studio Code on Windows

If you’ve ever tried uninstalling or updating Visual Studio Code and encountered this error:

> There was an error while deleting a directory… Access is denied (OS error 5)



You’re not alone. This issue usually appears when Windows prevents VS Code from deleting its own installation files — often because a process is still running or file permissions are corrupted.

Let’s break down why this happens and how to fix it properly.


---

🔍 Why This Error Happens

The error commonly points to a path like:

C:\Users\YourName\AppData\Local\Programs\Antigravity\resources

This happens due to:

VS Code still running in background

Electron process not closed properly

Interrupted auto-update

Windows permission corruption

Antivirus locking files


Windows blocks deletion because the folder is “in use” or you don’t fully own it.


---

✅ Step 1: Close All VS Code Processes

Before anything else, ensure nothing is running.

Method 1: Task Manager

1. Press Ctrl + Shift + Esc


2. End:

Code.exe

Visual Studio Code

Any electron.exe




Method 2: Command Line (Admin)

Open Command Prompt as Administrator and run:

taskkill /F /IM Code.exe
taskkill /F /IM electron.exe

Now retry uninstalling.


---

✅ Step 2: Take Ownership of the Folder

If access is still denied, it’s a permission issue.

Run this in Admin Command Prompt:

takeown /f "C:\Users\YourName\AppData\Local\Programs\Antigravity" /r /d y
icacls "C:\Users\YourName\AppData\Local\Programs\Antigravity" /grant %username%:F /t

This gives you full control over the directory.


---

✅ Step 3: Force Delete the Folder

Now remove it manually:

rmdir /s /q "C:\Users\YourName\AppData\Local\Programs\Antigravity"

If it deletes successfully, you’re done.


---

🔄 If It Still Fails

Option 1: Restart and Delete Immediately

Restart your PC and delete the folder before opening any applications.

Option 2: Use Safe Mode

Boot Windows into Safe Mode and delete the folder there. Safe Mode prevents background services from locking files.


---

🛠 Clean Reinstall (Recommended)

After deletion:

1. Download the latest VS Code installer


2. Right-click → Run as Administrator


3. Install fresh



This prevents corrupted auto-update files from returning.


---

💡 Pro Tips to Prevent This Issue

Always close VS Code before shutting down

Avoid force shutdown during updates

Keep Windows Defender exclusions clean

Prefer manual installer updates instead of auto-update



---

🚀 Final Thoughts

The “Access is denied (OS error 5)” problem isn’t a serious system issue — it’s almost always caused by a locked process or permission conflict. Once you kill background tasks and reclaim folder ownership, the problem disappears.

If you’re frequently switching between IDEs or testing environments, consider using portable installs to avoid permission conflicts altogether.

Happy coding 👨‍💻


🔎 Explanation of the Error

The message shown:

> There was an error while deleting a directory
C:\Users\rohit\AppData\Local\Programs\Antigravity\resources
Access is denied (OS error 5)
Please verify there are no Visual Studio Code processes still executing.




---

🧠 What This Actually Means

1️⃣ OS Error 5 = Permission Denied

Windows is refusing to delete that folder because:

The folder is currently in use

A process is locking it

You don’t have sufficient permission

Antivirus is protecting it


Windows protects active files from being deleted.


---

2️⃣ What is “Antigravity”?

Antigravity is the internal name of VS Code’s Electron-based installer/update engine.

So this error is not about your project —
it’s about VS Code trying to update or uninstall itself.


---

3️⃣ Why It Happens

Most common reasons:

Cause Explanation

VS Code still running Background process didn’t close
Auto-update crash PC shut down during update
Multiple instances Two VS Code sessions open
Antivirus lock Defender blocking file change
Corrupted permissions Windows ownership issue



---

4️⃣ What “resources” Folder Contains

The resources folder stores:

VS Code core files

Extensions runtime files

Electron app resources


If this folder is locked, update/uninstall fails.


---

⚠️ Is This Dangerous?

No.
It’s not a virus.
It’s not system corruption.
It’s just a locked file situation.


---

💡 In Simple Terms

Windows is saying:

> “I can’t delete this folder because something is still using it.”



That’s all.


---

If you want, I can also explain:

Why Electron apps cause this more often

Why WebStorm showed a similar directory lock error

How Windows file locking works internally


Just tell me.
Previous Post Next Post